我需要在django admin中为我的模型添加版本控制,因此我从here安装了django-reversion。我的服务器没有互联网连接,所以我无法使用pip。我不得不从github手动下载zip文件,将其上传到我的服务器,提取内容并运行python setup.py install
以安装reversion。
但是,当我尝试导入它时,出现以下错误:
root@ns1 /home/project# python
Python 2.7.3 (default, Feb 27 2013, 22:57:49)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 6, 0, 'final', 0)
>>> import reversion
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/reversion/__init__.py", line 11, in <module>
from reversion.revisions import default_revision_manager, revision_context_manager, VersionAdapter
File "/usr/local/lib/python2.7/site-packages/reversion/revisions.py", line 10, in <module>
from django.contrib.contenttypes.models import ContentType
File "/usr/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 1, in <module>
from django.db import models
File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 83, in <module>
signals.request_started.connect(reset_queries)
File "/usr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 88, in connect
if settings.DEBUG:
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
>>>
根据github页面,当前的版本是1.8.0,应该与django 1.6兼容。可能是什么问题?
答案 0 :(得分:1)
我知道这是一个老问题,但万一有人偶然发现它:这里的问题是你运行的是标准的python解释器,而不是Django shell。您可以import django
进入常规python解释器来检查Django版本,但它没有设置正确运行django所需的所有各种环境变量 - 包括导入django应用程序。要导入django应用程序,您需要通过
./ python manage.py shell