Home >Backend Development >Python Tutorial >Generating SECRET_KEY for production deployment of Django project

Generating SECRET_KEY for production deployment of Django project

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-31 08:32:16506browse

Generating SECRET_KEY for production deployment of Django project

Django SECRET_KEY need for providing cryptographic signing (documentation). This value is stored in /settings.py file. When you start new project it will be generated from built-in function (source code). For production deployment SECRET_KEY must be strong and reliably protected.

These steps help you for generating new SECRET_KEY value:

Activate your project's virtual environment:

source env/bin/activate

Enter in Django's manage.py shell:

python3 manage.py shell

Import get_random_secret_key() function:

from django.core.management.utils import get_random_secret_key

Just call get_random_secret_key() function:

get_random_secret_key()

Full example:

user@localhost:~/demo$ source env/bin/activate
(env) user@localhost:~/demo$ python3 manage.py shell
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.management.utils import get_random_secret_key
>>> get_random_secret_key()
'(#jdao11q1)kw1rs40z2$b^kntmw3ts9)wg2r*zk3z0_^t&hha'

Are my posts is helpful? You may support me on Patreon.

The above is the detailed content of Generating SECRET_KEY for production deployment of Django project. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn