mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
b0b600b79f
commit
dce718961c
4 changed files with 38 additions and 4 deletions
|
|
@ -1315,7 +1315,7 @@ Magic parameters all take this format: ``_prefix_rest_of_parameter``. The prefix
|
|||
|
||||
To register a new function, return it as a tuple of ``(string prefix, function)`` from this hook. The function you register should take two arguments: ``key`` and ``request``, where ``key`` is the ``rest_of_parameter`` portion of the parameter and ``request`` is the current :ref:`internals_request`.
|
||||
|
||||
This example registers two new magic parameters: ``:_request_http_version`` returning the HTTP version of the current request, and ``:_uuid_new`` which returns a new UUID:
|
||||
This example registers two new magic parameters: ``:_request_http_version`` returning the HTTP version of the current request, and ``:_uuid_new`` which returns a new UUID. It also registers an `:_asynclookup_key` parameter, demonstrating that these functions can be asynchronous:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
|
@ -1337,11 +1337,15 @@ This example registers two new magic parameters: ``:_request_http_version`` retu
|
|||
raise KeyError
|
||||
|
||||
|
||||
async def asynclookup(key, request):
|
||||
return await do_something_async(key)
|
||||
|
||||
@hookimpl
|
||||
def register_magic_parameters(datasette):
|
||||
return [
|
||||
("request", request),
|
||||
("uuid", uuid),
|
||||
("asynclookup", asynclookup),
|
||||
]
|
||||
|
||||
.. _plugin_hook_forbidden:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue