Skip to content

Unveiling Python's Hidden Gems: Exploring the Secrets Module

The secrets module in Python is a powerhouse when it comes to handling sensitive data such as passwords, API keys, and cryptographic tokens. Its primary purpose? Generating cryptographically strong random numbers suitable for managing data in a secure manner.

Starting in Django 3.0 the key begins with django-insecure as an additional prompt to tell developers not to use this specific key in production.

SECRET_KEY

import secrets
print(secrets.token_urlsafe())

dir(secrets)
help(secrets)

Copy and paste this new value into the .env file.

.env
DEBUG=True
SECRET_KEY=imDnfLXy-8Y-YozfJmP2Rw_81YA_qx1XKl5FeY0mXyY

Reference