noobes
noobes

Reputation: 161

import django_tables2 error:unresolved import

Can anyone help me. I have just installed django-tables2 using easy_install and when i try to import django_tables2 as tables in forms.py it gives me error unresolved import: tables then i try to reinstall again django_tables2 and give me the result as shown below.

$ 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

Thank you very much for help.

updated question.

I am still trying to figure out this problem. I am posting a new error on why I cannot import. By using python manage.py shell i get this error. I have no idea what is that mean.

$ 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.

Can anyone help me?:( Help is very much appreciated. Thank you.

Upvotes: 1

Views: 2204

Answers (1)

Brett Thomas
Brett Thomas

Reputation: 19

django_tables requires that you actually be running within the django-"primed" python environment. You can access this by going to your project's directory and typing

python manage.py shell

Then you can import django_tables2 with no problems.

For further info, take a look at the following: https://docs.djangoproject.com/en/dev/ref/django-admin/

Note that this is not about the admin template site (despite the url), it's about the django-admin.py (system-wide) and manage.py (project-wide) "helper" applications. manage.py shell actually starts up a standard python shell with several pre-loaded environment variables and a few imports.

Upvotes: 1

Related Questions