WebFaction
Community site: login faq

Hi,

When I try and import my models after running python2.7, I am getting the following error:

>>> from polls.models import User
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "polls/models.py", line 1, in <module>
    from django.db import models
  File "/home/shopperspoll/webapps/django/lib/python2.7/django/db/__init__.py", line 14, in <module>
    if not settings.DATABASES:
  File "/home/shopperspoll/webapps/django/lib/python2.7/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/home/shopperspoll/webapps/django/lib/python2.7/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.

I was wondering if I'm doing something wrong here? The models are getting imported properly in my views.py methods which get called on going to my site.

asked 10 Dec '11, 15:21

iman453
491527
accept rate: 0%


If you're playing with Django directly from Python, and not from Django's own manage.py shell, then you need to set the DJANGO_SETTINGS_MODULE variable before launching Python.

For example, if you have a Django project named "myproject", then run the following before launching Python:

export DJANGO_SETTINGS_MODULE=myproject.settings

For Apache to pick up that variable, you need to set it in httpd.conf as follows:

SetEnv DJANGO_SETTINGS_MODULE myproject.settings
permanent link

answered 10 Dec '11, 15:54

timg ♦♦
1.3k4
accept rate: 30%

edited 10 Dec '11, 16:47

seanf
12.2k41836

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×27

question asked: 10 Dec '11, 15:21

question was seen: 4,262 times

last updated: 10 Dec '11, 16:47

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM