我正在关注django heroku教程。我正处于'定义配置变量'这一点。我已经在我的views.py
中导入了import os
并像这样修改它
def index(request):
times = int(os.environ.get('TIMES',3))
return HttpResponse('Hello! ' * times)
我创建了一个.env文件
python-getting-started\
getting-started\
hello\
.env
教程说
heroku local will automatically set up the environment based on
the contents of the .env file in your local directory.
Edit the .env file to add:TIMES=2
If you run the app with heroku local, you’ll see two “Hello!”’s.
在我改变之后,我仍然看到“你好”三次。我重启了本地服务器三次但是没有用。我想让这个工作,所以我可以删除所有需要变量的硬编码的东西,所以我的应用程序是安全的。我错过了什么?欢迎所有指导。
答案 0 :(得分:1)
只是想确定一下。您的env变量中是否设置了TIMES
?你可以heroku config:get TIMES
查看它。如果没有设置,您有两个选择。通过命令行或herokus web app设置变量。
最后,如果一切都完成了。检查您的本地环境文件和heroku配置变量是否相同(除非您故意运行两个不同的设置)。