Skip to main content

SessionStorage

Store messages in the session (that is, django.contrib.sessions).

Attributes

AttributeTypeDescription
session_keystring = "_messages"The dictionary key used to store and retrieve serialized message data within the Django session object.

Constructor

Signature

def SessionStorage(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest),
*args: any,
**kwargs: any
)

Parameters

NameTypeDescription
request[HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest)The current HTTP request object which must contain a session attribute.
*argsanyVariable length argument list.
**kwargsanyArbitrary keyword arguments.

Methods


serialize_messages()

@classmethod
def serialize_messages(
messages: list
) - > string

Converts a list of message objects into a JSON-formatted string using a specialized encoder.

Parameters

NameTypeDescription
messageslistThe list of message instances to be encoded.

Returns

TypeDescription
stringA JSON string representation of the messages suitable for session storage.

deserialize_messages()

@classmethod
def deserialize_messages(
data: string
) - > list

Parses a JSON string from the session and reconstructs the original message objects.

Parameters

NameTypeDescription
datastringThe raw session data string to be decoded into message objects.

Returns

TypeDescription
listA list of message objects decoded from the input data, or the original data if it is not a valid string.