我正在嘗試將 heroku 上托管的 djnago 應用程序連接到 mongodb atlas。我還將 heroku 設置上的 DATABASE_URL 更改為:mongodb+srv://<name>:<password>@cluster0.wtnph.mongodb.net/test我正在使用 python 3.9 和 django 3.0.5 但是當部署到 heroku 時,我收到錯誤。> -----> Python app detected-----> No change in requirements detected, installing from cache-----> Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2-----> Installing SQLite3-----> Installing requirements with pip-----> $ python manage.py collectstatic --noinput Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 345, in execute settings.INSTALLED_APPS File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__ self._setup(name) File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup self._wrapped = Settings(settings_module) File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 142, 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)我什至嘗試從 Settings.py 中刪除 DATABASE 字典
1 回答

滄海一幻覺
TA貢獻1824條經驗 獲得超5個贊
我能夠通過更改 settings.py 中的這一行來解決該問題
從:
# Activate Django-Heroku.
django_heroku.settings(locals()),
到:
# Activate Django-Heroku.
django_heroku.settings(locals(), databases=False),
添加回答
舉報
0/150
提交
取消