SessionStorage
Store messages in the session (that is, django.contrib.sessions).
Attributes
| Attribute | Type | Description |
|---|---|---|
| session_key | string = "_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
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The current HTTP request object which must contain a session attribute. |
| *args | any | Variable length argument list. |
| **kwargs | any | Arbitrary 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
| Name | Type | Description |
|---|---|---|
| messages | list | The list of message instances to be encoded. |
Returns
| Type | Description |
|---|---|
string | A 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
| Name | Type | Description |
|---|---|---|
| data | string | The raw session data string to be decoded into message objects. |
Returns
| Type | Description |
|---|---|
list | A list of message objects decoded from the input data, or the original data if it is not a valid string. |