具有生成django密钥的命令的django应用程序
django-generate-secret-ke的Python项目详细描述
添加新命令的简单django应用程序:
python manage.py generate_secret_key [--replace][secretkey.txt]
这将生成包含随机django机密的新文件secretkey.txt。 钥匙在生产设置文件中,将硬编码密钥替换为:
# Use a separate file for the secret keywithopen('/path/to/the/secretkey.txt')asf:SECRET_KEY=f.read().strip()
您可以使用:
importosBASE_DIR=os.path.dirname(os.path.dirname(__file__))# Use a separate file for the secret keywithopen(os.path.join(BASE_DIR,'secretkey.txt'))asf:SECRET_KEY=f.read().strip()