django - 在 heroku 上运行基于 geodjango 的应用程序时出错

标签 django heroku geodjango

问题

我正在尝试将我的 geodjango 应用程序部署到 Heroku。应用程序运行,但是当我尝试查看 /admin/world/worldborder/ 时( the wolrd geodjango tutorial application ) 或我自己的自定义 Spots 应用程序(使用 geodjango)然后网站崩溃。

如果我查看我的 heroku logs然后我看到测功机出现 500 错误:

2012-07-20T08:16:23+00:00 heroku[router]: GET myapp.herokuapp.com/admin/spots/spot/ dyno=web.1 queue=0 wait=0ms service=654ms status=500 bytes=4922

然后我通过电子邮件收到此错误:
AttributeError: 'module' object has no attribute 'GeoSQLCompiler'

完整的回溯可以找到 here

我在其他地方的 aws ec2 实例上有我的数据库服务器,并且已经通过 these installation instructions在那台服务器上。

应用上下文

Django ==1.4
unicorn ==0.14.2

我使用以下内容创建了我的 heroku 应用程序
heroku create myapp --stack cedar --buildpack http://github.com/cirlabs/heroku-buildpack-geodjango/

如您所见,我使用的是 custom buildpack为 geodjango 安装所有必要的东西。如果我不使用此自定义 buildpack 并简单地使用 heroku create myapp然后我得到 this long error .

我还将这些添加到 heroku 配置变量中
GEOS_LIBRARY_PATH='/app/.geodjango/geos/lib/libgeos_c.so'
GDAL_LIBRARY_PATH='/app/.geodjango/gdal/lib/libgdal.so'

我已经尝试过的

我用谷歌搜索了这个错误,只发现一篇帖子 here .基本上说要确保我的数据库后端正确设置为使用(我已经这样做了)
'ENGINE': 'django.contrib.gis.db.backends.postgis',

我还尝试更改为以下内容:
GEOS_LIBRARY_PATH='/myapp/.geodjango/geos/lib/libgeos_c.so'
GDAL_LIBRARY_PATH='/myapp/.geodjango/gdal/lib/libgdal.so'

此应用程序可以在我的本地开发机器上正常运行 python manage.py runserverforeman start -f Profile.dev
为什么我不能在 Heroku 上使用基于 geodjango 的应用程序,我该如何解决这个问题?

最佳答案

我有 93.2% 的把握这是 path问题。主要PITAs之一在 Web 开发中,您的命令行环境可能与服务器环境几乎没有任何共同之处。

当我需要确切知道从哪个目录加载哪些模块的哪个版本时,我使用以下内容。它返回一个 2 元组列表 ('name', 'path-to-module') .在您的初始化完成后调用它,或者在您尝试加载地理模块(或其他同样有趣的地方)之前和/或之后调用它,并将结果转储到屏幕或日志文件中。

我不知道这会解决你的问题,但它可能会给你一些有趣的见解。

注意:您可以编辑(或注释掉)re.sub()尝尝。我只是把它们放进去,因为一大页绝对路径名很难看,并且可以掩盖这样一个事实,即某些东西是从系统的副本而不是您自己的副本加载的。
modulelist.py

import sys, re, os
import django

def ModuleList():
    ret = []
    dir_project = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    project_name = os.path.basename(dir_project)

    for k,v in sys.modules.items():

        x = str(v)
        if 'built-in' in x:
            ret.append((k, 'built-in'))
            continue

        m = re.search(r"^.*?'(?P<module>.*?)' from '(?P<file>.*?)'.*$", x)
        if m:
            d = m.groupdict()
            f = d['file']
            f = re.sub(r'/usr/.*?/lib/python[.0-9]*/site-packages/django/', 'system django >> ', f)
            f = re.sub(r'/usr/.*?/lib/python[.0-9]*/site-packages/', 'site-packages >> ', f)
            f = re.sub(r'/usr/.*?/lib/python[.0-9]*/', 'system python >> ', f)
            f = re.sub(dir_project+'.*python/', 'local python >> ', f)
            f = re.sub(dir_project+'.*django/', 'local django >> ', f)
            f = re.sub(dir_project+r'(/\.\./)?', project_name + ' >> ', f)
            ret.append((d['module'], f))
    ret.sort( lambda a,b: cmp(a[0].lower(), b[0].lower()) )
    ret.insert(0, ('Python version', sys.version) )
    ret.insert(0, ('Django version', django.get_version()) )

    return ret
# ModuleList

if __name__ == "__main__":
    for x in ModuleList():
        print "%s\t%s" % (x[0], x[1])

关于django - 在 heroku 上运行基于 geodjango 的应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11576163/

相关文章:

python - 如何分配给 Django PointField 模型属性?

ruby - GIt 部署 + 配置文件 + Heroku

heroku - 将 Heroku 应用程序连接到私有(private) GitHub 存储库以在 Heroku 上部署

python - Django 测试 : error creating the test database: permission denied to copy database "template_postgis"

python - 我使用 python(django 框架)从 google api 获取请求 token ,但请求 token 总是返回空的

ruby-on-rails - Rails、Heroku 和 Resque : Workers stuck in infinite "working" state

django - 我的 PostGIS 数据库看起来不错,但 GeoDjango 不这么认为……为什么?

python - 关于集成 Django 和 Flex 的书

python - 对 modelform_factory 表单中的字段进行重新排序

python - 上传SimpleUploadedFile时BytesIO流图像为空白