dumps
Return URL-safe, hmac signed base64 compressed JSON string. If key is None, use settings.SECRET_KEY instead. The hmac algorithm is the default Signer algorithm.
If compress is True (not the default), check if compressing using zlib can
save some space. Prepend a '.' to signify compression. This is included
in the signature, to protect against zip bombs.
Salt can be used to namespace the hash, so that a signed string is
only valid for a given namespace. Leaving this at the default
value or re-using a salt value across different parts of your
application without good cause is a security risk.
The serializer is expected to return a bytestring.
def dumps(
obj: Any,
key: string = None,
salt: string = django.core.signing,
serializer: class = JSONSerializer,
compress: boolean = False
) - > string
Return URL-safe, hmac signed base64 compressed JSON string. If key is None, use settings.SECRET_KEY instead. The hmac algorithm is the default Signer algorithm.
Parameters
| Name | Type | Description |
|---|---|---|
| obj | Any | The Python object to be serialized and signed. |
| key | string = None | The secret key used to generate the HMAC signature; defaults to settings.SECRET_KEY if not provided. |
| salt | string = django.core.signing | A string used to namespace the hash, ensuring the signed string is only valid within a specific context to prevent signature reuse. |
| serializer | class = JSONSerializer | A serializer class responsible for converting the object into a bytestring before signing. |
| compress | boolean = False | If True, attempts to reduce the output size using zlib compression and prepends a '.' to the result. |
Returns
| Type | Description |
|---|---|
string | A URL-safe, signed, and optionally compressed base64 string representing the serialized object. |