summaryrefslogtreecommitdiff
path: root/docs/topics/http
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2023-02-09 16:48:46 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-10 21:12:06 +0100
commitb784768eef75afb32f6d2ce7166551a528bce0ec (patch)
treea375a57a50f1766538ea8a62ec49bda352d7f2b9 /docs/topics/http
parent4a89aa25c91e520c247aee428782274dcf10ffd0 (diff)
[4.2.x] Refs #34140 -- Applied rst code-block to non-Python examples.
Thanks to J.V. Zammit, Paolo Melchiorre, and Mariusz Felisiak for reviews. Backport of 534ac4829764f317cf2fbc4a18354fcc998c1425 from main.
Diffstat (limited to 'docs/topics/http')
-rw-r--r--docs/topics/http/sessions.txt18
1 files changed, 14 insertions, 4 deletions
diff --git a/docs/topics/http/sessions.txt b/docs/topics/http/sessions.txt
index 4dc6f6af35..cfc22bee52 100644
--- a/docs/topics/http/sessions.txt
+++ b/docs/topics/http/sessions.txt
@@ -357,7 +357,9 @@ Bundled serializers
only serialize basic data types.
In addition, as JSON supports only string keys, note that using non-string
- keys in ``request.session`` won't work as expected::
+ keys in ``request.session`` won't work as expected:
+
+ .. code-block:: pycon
>>> # initial assignment
>>> request.session[0] = 'bar'
@@ -499,11 +501,15 @@ Using sessions out of views
you should consider importing ``SessionStore`` from the session engine
designated by :setting:`SESSION_ENGINE`, as below:
+ .. code-block:: pycon
+
>>> from importlib import import_module
>>> from django.conf import settings
>>> SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
-An API is available to manipulate session data outside of a view::
+An API is available to manipulate session data outside of a view:
+
+.. code-block:: pycon
>>> from django.contrib.sessions.backends.db import SessionStore
>>> s = SessionStore()
@@ -526,7 +532,9 @@ calls ``save()`` and loops until an unused ``session_key`` is generated.
If you're using the ``django.contrib.sessions.backends.db`` backend, each
session is a normal Django model. The ``Session`` model is defined in
:source:`django/contrib/sessions/models.py`. Because it's a normal model, you can
-access sessions using the normal Django database API::
+access sessions using the normal Django database API:
+
+.. code-block:: pycon
>>> from django.contrib.sessions.models import Session
>>> s = Session.objects.get(pk='2b1189a188b44ad18c35e113ac6ceead')
@@ -536,7 +544,9 @@ access sessions using the normal Django database API::
Note that you'll need to call
:meth:`~base_session.AbstractBaseSession.get_decoded()` to get the session
dictionary. This is necessary because the dictionary is stored in an encoded
-format::
+format:
+
+.. code-block:: pycon
>>> s.session_data
'KGRwMQpTJ19hdXRoX3VzZXJfaWQnCnAyCkkxCnMuMTExY2ZjODI2Yj...'