Skip to content

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

  1. Initialize your project (only once)
uv init
  1. Add Jurigged as a development dependency
uv add --dev jurigged
  1. Run your app with hot reload

uv run -m jurigged app.py
reload watches for code changes and reloads the server automatically.

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
This will generate a compatible file for tools and environments that require it.

How do I run Tina4 under hypercorn, uvicorn or other ASGI servers?

  1. Expose the ASGI app in app.py:

    app.py
    # change the import
    from tina4_python import app
    

  2. 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))