没有名为常量的模块 [英] No module named constants
问题描述
我想使用Tastypie框架来做示例应用程序。
I want to do sample application with Tastypie framework.
我在已安装的应用程序中添加了Tastypie并修改了 urls.py
,根据需要,从tastypie.api import Api添加
。但是当我打开 http:// localhost:8000 / api / v1 /?format = json
时,出现以下异常:
I added Tastypie to Installed app and modified urls.py
as required, adding from tastypie.api import Api
. But when I open http://localhost:8000/api/v1/?format=json
, I get the following exception:
异常值:没有名为常量的模块
Exception Value: No module named constants
我运行时:
pip install constants
一切看起来都很好。
Python 2.6 (and try on 2.7)
Django 1.4
Tastypie 0.10.0
推荐答案
问题出在 resources.py
文件来获取密码。它包含以下行:
the problem is in the resources.py
file for tastypie. It has the following line:
from django.db.models.constants import LOOKUP_SEP
该导入仅适用于1.5+版本。对于Django< 1.5,应该是:
That import will only work on 1.5+. For django < 1.5, it should be:
from django.db.models.sql.constants import LOOKUP_SEP
升级到1.5绝对可以解决问题,但是对于那些无法升级的人,可以暂时将其降级或自己修复。
Upgrading to 1.5 will definitely fix it, but for those who can't, temporarily downgrade tastypie or do that fix yourself.
这篇关于没有名为常量的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!