diff --git a/docs/config.rst b/docs/config.rst index ff39f02a..0883e532 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -220,6 +220,7 @@ HTML page. Set this to 0 to disable truncation. datasette mydatabase.db --config truncate_cells_html:0 +.. _config_force_https_urls: force_https_urls ~~~~~~~~~~~~~~~~ diff --git a/docs/internals.rst b/docs/internals.rst index 1c714eb8..4ebeb983 100644 --- a/docs/internals.rst +++ b/docs/internals.rst @@ -332,6 +332,26 @@ Datasette's flash messaging mechanism allows you to add a message that will be d You can try out these messages (including the different visual styling of the three message types) using the ``/-/messages`` debugging tool. +.. _datasette_absolute_url: + +.absolute_url(request, path) +---------------------------- + +``request`` - Request + The current Request object + +``path`` - string + A path, for example ``/dbname/table.json`` + +Returns the absolute URL for the given path, including the protocol and host. For example: + +.. code-block:: python + + absolute_url = datasette.absolute_url(request, "/dbname/table.json") + # Would return "http://localhost:8001/dbname/table.json" + +The current request object is used to determine the hostname and protocol that should be used for the returned URL. The :ref:`config_force_https_urls` configuration setting is taken into account. + .. _internals_datasette_client: datasette.client