You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The quickest way to create responses is using the ``Response.text(...)``, ``Response.html(...)``, ``Response.json(...)`` or ``Response.redirect(...)`` helper methods:
@@ -157,9 +157,13 @@ The quickest way to create responses is using the ``Response.text(...)``, ``Resp
Each of these responses will use the correct corresponding content-type - ``text/html; charset=utf-8``, ``application/json; charset=utf-8`` or ``text/plain; charset=utf-8`` respectively.
165
169
@@ -207,13 +211,17 @@ To set cookies on the response, use the ``response.set_cookie(...)`` method. The
207
211
httponly=False,
208
212
samesite="lax",
209
213
):
214
+
...
210
215
211
216
You can use this with :ref:`datasette.sign() <datasette_sign>` to set signed cookies. Here's how you would set the :ref:`ds_actor cookie <authentication_ds_actor>` for use with Datasette :ref:`authentication <authentication>`:
@@ -345,7 +356,7 @@ This is useful when you need to check multiple permissions at once. For example,
345
356
("view-table", (database, table)),
346
357
("view-database", database),
347
358
"view-instance",
348
-
]
359
+
],
349
360
)
350
361
351
362
.. _datasette_check_visibilty:
@@ -406,20 +417,26 @@ The ``db`` parameter should be an instance of the ``datasette.database.Database`
406
417
407
418
from datasette.database import Database
408
419
409
-
datasette.add_database(Database(
410
-
datasette,
411
-
path="path/to/my-new-database.db",
412
-
is_mutable=True
413
-
))
420
+
datasette.add_database(
421
+
Database(
422
+
datasette,
423
+
path="path/to/my-new-database.db",
424
+
is_mutable=True,
425
+
)
426
+
)
414
427
415
428
This will add a mutable database and serve it at ``/my-new-database``.
416
429
417
430
``.add_database()`` returns the Database instance, with its name set as the ``database.name`` attribute. Any time you are working with a newly added database you should use the return value of ``.add_database()``, for example:
418
431
419
432
.. code-block:: python
420
433
421
-
db = datasette.add_database(Database(datasette, memory_name="statistics"))
# Would return "http://localhost:8001/dbname/table.json"
521
539
522
540
The current request object is used to determine the hostname and protocol that should be used for the returned URL. The :ref:`setting_force_https_urls` configuration setting is taken into account.
@@ -578,7 +596,9 @@ These methods can be used with :ref:`internals_datasette_urls` - for example:
0 commit comments