Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django.env文件的工作方式与教程中的解释不一样_Python_Django_Heroku - Fatal编程技术网

Python django.env文件的工作方式与教程中的解释不一样

Python django.env文件的工作方式与教程中的解释不一样,python,django,heroku,Python,Django,Heroku,我正在学习django heroku教程。我正处于“定义配置变量”的位置。我已在my 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\

我正在学习django heroku教程。我正处于“定义配置变量”的位置。我已在my 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.

在我修改它之后,我仍然看到“你好”三次。我重新启动了本地服务器三次,但没有成功。我想让它工作,这样我就可以删除所有硬编码的东西,需要成为变量,所以我的应用程序是安全的。我错过了什么?欢迎提供所有指导。

我只是想确定一下。环境变量中是否设置了
时间
?您可以执行
heroku config:get TIMES
来检查它。如果未设置,则有两个选项。通过命令行或herokus web app设置变量

最后,如果所有这些都完成了。检查您的本地env文件和heroku配置变量是否相同(除非您有意运行两种不同的设置)