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
Nunyet Calçada
1,62257 gold badges204 silver badges338 bronze badges
-
Did you set up a database? docs.djangoproject.com/en/1.8/intro/tutorial01/#database-setupcircuitBurn– circuitBurn2015年07月28日 17:17:41 +00:00Commented Jul 28, 2015 at 17:17
2 Answers 2
Use manage.py, not django-admin.
answered Jul 28, 2015 at 17:16
Daniel Roseman
602k68 gold badges911 silver badges924 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
Christine Schäpers
1,34810 silver badges18 bronze badges
Comments
lang-py