[英]When deploying Django to Heroku: ModuleNotFoundError: No module named 'env'
When deploying Django to Heroku, I get a ModuleNotFoundError: No module named 'env' error.将 Django 部署到 Heroku 时,我收到 ModuleNotFoundError: No module named 'env' 错误。
Anyone know why it is looking for that module?有人知道它为什么要寻找那个模块吗?
Here is my requirements.txt:这是我的requirements.txt:
asgiref==3.2.3
certifi==2020.12.5
chardet==3.0.4
dj-database-url==0.5.0
Django==1.11
django-forms-bootstrap==3.1.0
gunicorn==20.0.4
idna==2.10
Pillow==5.3.0
psycopg2==2.8.6
pytz==2020.4
requests==2.25.0
sqlparse==0.4.1
stripe==2.55.1
urllib3==1.26.2
whitenoise==5.2.0
Here is the build log from Heroku:这是来自 Heroku 的构建日志:
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 307, in execute
settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/tmp/build_ae2377c8_/issuetracker/settings.py", line 15, in <module>
import env
ModuleNotFoundError: No module named 'env'
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
either remove the import env
code from the settings.py file and run this code从 settings.py 文件中删除
import env
环境代码并运行此代码
heroku config:set DISABLE_COLLECTSTATIC=1
I remember how to get around this problem now.我记得现在如何解决这个问题。 I needed to add to my settings file:
我需要添加到我的设置文件:
if os.path.exists('env.py'):
import env
Heroku is working again. Heroku 再次工作。
Thanks for your answers.感谢您的回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.