#python #django #heroku #pymongo
#python #django #heroku #pymongo
Вопрос:
Я пытаюсь подключить мое приложение djnago, размещенное на heroku, к mongodb atlas. Я также изменил DATABASE_URL в настройках heroku как:
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)
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_91bba5c0/kibo_skill_matrix_api/settings.py", line 176, in <module>
django_heroku.settings(locals())
File "/app/.heroku/python/lib/python3.6/site-packages/django_heroku/core.py", line 69, in settings
config['DATABASES']['default'] = dj_database_url.config(conn_max_age=MAX_CONN_AGE, ssl_require=True)
File "/app/.heroku/python/lib/python3.6/site-packages/dj_database_url.py", line 55, in config
config = parse(s, engine, conn_max_age, ssl_require)
File "/app/.heroku/python/lib/python3.6/site-packages/dj_database_url.py", line 103, in parse
engine = SCHEMES[url.scheme] if engine is None else engine
KeyError: 'mongodb srv'
If you suspect this is an IPython 7.16.1 bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org
Я даже пытался удалить dict базы данных из Settings.py
Ответ №1:
Я смог решить проблему, изменив эту строку в settings.py
От:
# Activate Django-Heroku.
django_heroku.settings(locals()),
Для:
# Activate Django-Heroku.
django_heroku.settings(locals(), databases=False),