【问题标题】:Using python models in Django Models在 Django 模型中使用 python 模型
【发布时间】:2014-06-04 02:35:50
【问题描述】:

以下是我的 Django 应用程序的 models.py:

from django.db import models
from djorm_pgarray.fields import ArrayField
from djorm_expressions.models import ExpressionManager

class Device(models.Model):
    child_devices = ArrayField(dbtype='text')
    ....

所以基本上,我使用名为“djorm_pgarray”的 python 模型在我的 Django 模型中使用 Postgresql 的 ARRAY 数据类型。

显然我安装了在虚拟环境中键入的包:

pip install djorm-ext-pgarray

当我同步并运行 Django 服务器并尝试加载管理页面时,我收到此错误:

   ImportError at /admin/
    No module named djorm_pgarray
    Request Method: GET
    Request URL:    http://agile-woodland-9781.herokuapp.com/admin/
    Django Version: 1.6.2
    Exception Type: ImportError
    Exception Value:    
    No module named djorm_pgarray
    Exception Location: /app/app_search/models.py in <module>, line 2
    Python Executable:  /app/.heroku/python/bin/python
    Python Version: 2.7.6
    Python Path:    
    ['/app',
     '/app/.heroku/python/bin',
     '/app/.heroku/python/lib/python2.7/site-packages/setuptools-2.1-py2.7.egg',
     '/app/.heroku/python/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg',
     '/app',
     '/app/.heroku/python/lib/python27.zip',
     '/app/.heroku/python/lib/python2.7',
     '/app/.heroku/python/lib/python2.7/plat-linux2',
     '/app/.heroku/python/lib/python2.7/lib-tk',
     '/app/.heroku/python/lib/python2.7/lib-old',
     '/app/.heroku/python/lib/python2.7/lib-dynload',
     '/app/.heroku/python/lib/python2.7/site-packages']
    Server time:    Sat, 19 Apr 2014 17:52:35 +0000

如何在 Django 模型中导入和使用 python 模块?

谢谢

【问题讨论】:

  • 我看到你正在使用 heroku。您是否记得将 djorm-ext-pgarray 添加到您的 requirements.txt 文件中?
  • 用pip安装的时候virtualenv激活了吗?

标签: python django postgresql heroku


【解决方案1】:

确保:

  1. pip install djorm-ext-pgarray 在你的虚拟环境中执行
  2. pip freeze &gt; requirements.txt 正确更新您的文件
  3. requirements.txt 的更改已提交到 git 并正确推送到 Heroku

【讨论】:

  • 有同样的问题,确实是没有安装库的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-30
  • 1970-01-01
  • 1970-01-01
  • 2021-07-31
  • 2013-05-28
  • 2021-08-24
  • 2021-09-29
相关资源
最近更新 更多