在Heroku上使用Django运行PostGIS

编程入门 行业动态 更新时间:2024-10-28 16:25:07
本文介绍了在Heroku上使用Django运行PostGIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试在Heroku上运行GeoDjango应用程序,这确实是一项工作.在解决了各种问题之后,我遇到了一个似乎无法摆脱困境的问题.

Trying to run a GeoDjango app on Heroku and it's being a really piece of work. After struggling through a variety of problems, I've come to one I can't seem to hack my way out of.

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 673, in db_parameters type_string = self.db_type(connection) File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/gis/db/models/fields.py", line 105, in db_type return connection.ops.geo_db_type(self) AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'

我已经正确地使用了dj-database-url来设置引擎,但是我仍然看到错误

I have properly used dj-database-url to set the engine, however I'm still seeing the error

我添加了一条print语句来输出我的数据库设置,因为它们正在被py解释

I added a print statement to output my db setups as they're being interpreted by py

在settings.py中:

if os.getenv('DYNO'): GDAL_LIBRARY_PATH = os.path.expandvars(os.getenv('GDAL_LIBRARY_PATH')) GEOS_LIBRARY_PATH = os.path.expandvars(os.getenv('GEOS_LIBRARY_PATH')) DATABASES['default'] = dj_database_url.parse(os.getenv('DATABASE_URL'),'django.contrib.gis.db.backends.postgis') print(DATABASES['default'])

这是打印语句,输出heroku服务器解释为我的DATABASES['default']凭据

Here is the print statement outputting what the heroku server is interpreting as my DATABASES['default'] credentials

{'NAME': 'name', 'USER': 'usr', 'PASSWORD': 'pw', 'HOST': 'herokuec2host.amazonaws', 'PORT': 5432, 'CONN_MAX_AGE': 0, 'ENGINE': 'django.contrib.gis.db.backends.postgis'}

任何帮助表示赞赏.我知道有关此问题的各种类似stackoverflow帖子,但是我研究过的所有解决方案都没有解决问题-请再问一遍.

Any help appreciated. I'm aware of the various similar stackoverflow posts regarding this issue, however all of the solutions I've researched have not solved the issue -- so asking again.

推荐答案

Geodjango需要连接"postgis://...",但是heroku将数据库设置更改为"postgres://".因此,如果将DATABASES变量移到settings.py中的底部,则问题已解决.快乐黑客:)

Geodjango need to connect "postgis://..." but heroku change db settings to "postgres://". So, if you move DATABASES variable to bottom in settings.py, problem has been resolved. Happy hacking :)

django_heroku.settings(locals()) DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': '*', 'USER': '*', 'PASSWORD': '*', 'HOST': '*', 'PORT': '5432', }, }

更多推荐

在Heroku上使用Django运行PostGIS

本文发布于:2023-10-13 09:24:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Heroku   Django   PostGIS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!