在同一个目录下manage.py,创建一个名为 的文件.env,并将其放入其中:SECRET_KEY = '....your secret key ....' # --- the one indicated in your settings.py, cut an paste it hereSECRET_KEY = '....your secret key ....'你的settings.py.因此,请从您的文件中剪切此行settings.py并将其粘贴到.env文件中。在同一目录中,创建一个名为 的文件.gitignore,并将其放入其中:.env然后在settings.py你之前的地方SECRET_KEY = '....your secret key ....',输入:from decouple import config
SECRET_KEY = config("SECRET_KEY") # this is to replace the secret key you cut away before然后在命令提示符下运行:pip install python-decouple
pip freeze > requirements.txt然后在Github上添加、提交和推送。