Distributing Django projects with unique SECRET_KEYs

前端 未结 10 954
长发绾君心
长发绾君心 2020-12-22 16:41

I have a Django project that I\'d like to distribute on a public repository like bitbucket or github. I\'d like it to be as easy to install as possible, so I\'m including t

10条回答
  •  旧时难觅i
    2020-12-22 17:18

    To add to what Carles Barrobés said, you can generate a new key using the method that Django uses in startproject:

    from django.utils.crypto import get_random_string
    
    chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
    get_random_string(50, chars)
    

    For Django 1.10 and above, the above code snippet is nicely wrapped up in a function.

    from django.core.management.utils import get_random_secret_key
    get_random_secret_key()
    

    Link to GitHub repo

提交回复
热议问题