Skip to main content

Django SECRET_KEY management

Project description

In Django web framework, it has SECRET_KEY variable in this variable use to manage credential values like session.

Therefore, SECRET_KEY value have to store outside of and use this value to read from file or environment variables.


pip instal djangosecretkey

This project has not any dependencies. (For test, needs pytest package) You cannot download yet


Use file to store secret key


import os
from secret_key import secret_key
# ...
SECRET_KEY = secret_key.from_file(os.path.join(BASE_DIR, 'secret_key'))

If use .from_file() method, you have to secert key file add to .gitignore

Use env to store secret key


import os
from secret_key import secret_key
# ...
SECRET_KEY = secret_key.from_env('env_name')

default env_name is “DJANGO_SECRET_KEY”

Generate secret key manually

You can also generate secret key manually.

import os
from secret_key import secret_key
# ...
SECRET_KEY = secret_key.generate()

But, this method not recommanded.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for DjangoSecretKey, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size DjangoSecretKey-0.1.0-py3-none-any.whl (3.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size DjangoSecretKey-0.1.0.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page