1

I am a newbie in Django un I want to write a Test for Django Web-poll application (https://docs.djangoproject.com/en/1.8/intro/tutorial01/)

but I got this error:

devuser@localhost:~/Django-apps/poolApp$ django-admin shell --plain --no-startup
Traceback (most recent call last):
 File "/usr/local/bin/django-admin", line 9, in <module>
 load_entry_point('Django==1.8.3', 'console_scripts', 'django-admin')()
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/core/management/__init__.py", line 338, in execute_from_command_line
 utility.execute()
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/core/management/__init__.py", line 330, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/core/management/base.py", line 405, in run_from_argv
 connections.close_all()
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/db/utils.py", line 258, in close_all
 for alias in self:
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/db/utils.py", line 252, in __iter__
 return iter(self.databases)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/utils/functional.py", line 60, in __get__
 res = instance.__dict__[self.name] = self.func(instance)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/db/utils.py", line 151, in databases
 self._databases = settings.DATABASES
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/conf/__init__.py", line 48, in __getattr__
 self._setup(name)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/conf/__init__.py", line 42, in _setup
 % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I would like to know what is the best approach to do it:

define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure()

asked Jul 28, 2015 at 17:12
1

2 Answers 2

5

Use manage.py, not django-admin.

answered Jul 28, 2015 at 17:16
Sign up to request clarification or add additional context in comments.

Comments

3

What does work is using

django-admin shell --plain --no-startup --pythonpath "." --settings "myproject.settings"

while you are in the root of your django app.

However manage.py shell (or the amazing shell_plus from django_extensions https://github.com/django-extensions/django-extensions) is recommended instead

answered Jul 28, 2015 at 17:21

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.