kopia lustrzana https://github.com/simonw/datasette
Updated example for extra_template_vars hook, closes #816
rodzic
040fc0546f
commit
c7d145e016
|
@ -689,14 +689,14 @@ Function that returns an awaitable function that returns a dictionary
|
|||
|
||||
Datasette runs Jinja2 in `async mode <https://jinja.palletsprojects.com/en/2.10.x/api/#async-support>`__, which means you can add awaitable functions to the template scope and they will be automatically awaited when they are rendered by the template.
|
||||
|
||||
Here's an example plugin that returns an authentication object from the ASGI scope:
|
||||
Here's an example plugin that adds a ``"user_agent"`` variable to the template context containing the current request's User-Agent header:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@hookimpl
|
||||
def extra_template_vars(request):
|
||||
return {
|
||||
"auth": request.scope.get("auth")
|
||||
"user_agent": request.headers.get("user-agent")
|
||||
}
|
||||
|
||||
This example returns an awaitable function which adds a list of ``hidden_table_names`` to the context:
|
||||
|
|
Ładowanie…
Reference in New Issue