import django_tables2错误:未解析的导入

时间:2012-10-18 14:40:58

标签: django django-forms django-views

任何人都可以帮助我。我刚刚使用easy_install安装了django-tables2,当我在forms.py中尝试import django_tables2 as tables时,它给了我错误unresolved import: tables然后我尝试重新安装django_tables2并给我结果,如下所示。

$ easy_install django_tables2
Searching for django-tables2
Best match: django-tables2 0.13.0
Processing django_tables2-0.13.0-py2.7.egg
django-tables2 0.13.0 is already the active version in easy-install.pth

Using c:\python27\lib\site-packages\django_tables2-0.13.0-py2.7.egg
Processing dependencies for django-tables2
Finished processing dependencies for django-tables2

非常感谢您的帮助。

更新了问题。

我仍在努力解决这个问题。我发布了一个关于无法导入的新错误。使用python manage.py shell我收到此错误。我不知道那是什么意思。

$ python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django_tables2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win32\egg\django_tables2\__init__.py", line 3, in <module>
File "build\bdist.win32\egg\django_tables2\tables.py", line 4, in <module>
File "c:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "c:\Python27\lib\site-packages\django\utils\functional.py", line 184, in inner
self._setup()
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is         undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable     DJANGO_SETTINGS_MODULE is undefined.

任何人都可以帮助我吗?:(非常感谢帮助。谢谢。

1 个答案:

答案 0 :(得分:2)

django_tables要求你实际上在django-“primed”python环境中运行。您可以通过转到项目目录并键入

来访问它
python manage.py shell

然后你可以毫无问题地导入django_tables2。

有关详细信息,请查看以下内容: https://docs.djangoproject.com/en/dev/ref/django-admin/

请注意,这不是关于管理模板站点(尽管是url),而是关于django-admin.py(系统范围)和manage.py(项目范围)“帮助”应用程序。 manage.py shell实际上启动了一个带有几个预先加载的环境变量和一些导入的标准python shell。

相关问题