Questions & Answers
The following collection of Questions and Answers should make you more efficient in using the framework!
Create a simple Get route
from tina4_python.Router import get
@get("/route/name")
async def get_route(request, response):
return response("Route")
Redirect
from tina4_python.Router import get
@get("/route/name")
async def get_route(request, response):
return response.redirect("/login")
Create a simple Post route
from tina4_python.Router import post
@post("/route/name")
async def post_route(request, response):
return response("Route")
Render a Jinja2/Twig template
from tina4_python.Router import get
from tina4_python.Template import Template
@get("/render/template")
async def get_render_template(request, response):
html = Template.render_twig_template("template.twig", data={})
return response(html)
Annotate routes for OpenAPI
from tina4_python.Router import post
from tina4_python.Swagger import description, summary, example, tags, secure
@post("/api/{name}")
@description("Some description")
@summary("Some summary")
@example({"id": 1, "name": "Test"})
@tags(["user", "admin"])
@secure()
async def post_route(request, response):
return response("OK")
How do I get hot code reloading?
Use Jurigged during development to watch for code changes and reload your app automatically.
Installing Jurigged with uv
- Initialize your project (only once)
uv init
- Add Jurigged as a development dependency
uv add --dev jurigged
- Run your app with hot reload
uv run -m jurigged app.py
How do I deploy the application for production?
When deploying your app to production:
uv sync --no-dev
How to generate a requirements.txt using UV?
uv pip freeze > requirements.txt
How do I run Tina4 under hypercorn, uvicorn or other ASGI servers?
-
Expose the ASGI
app
inapp.py
:app.py# change the import from tina4_python import app
-
Then install and run with:
uv add hypercorn
hypercorn app:app
How do implement logging in my application
from tina4_python import Debug
Debug.info("This is information")
Debug.debug("This is debugging")
Debug.error("This is an error")
Debug.warning("This is a warning")
How do I get a fresh formToken for my form
{{ ("SomeValue"~RANDOM()) | formToken }}
How do I manipulate the DatabaseResult set with a method/ function filter
def change_me(record):
record["value"] = "Something Else"
return record
result = dba.fetch("select * from users")
print (result.to_list(change_me))