remember Tutorial users to invoke the shell by "python manage.py shell" before setting up the test environment
|Reported by:||anonymous||Owned by:||MaxV|
|Severity:||Normal||Keywords:||"Tutorial 1.5" / "Test a view", afraid-to-commit|
|Cc:||st.sempert@…, EvilDMP, MaxV||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Working through the Tutorial 5 I stumbled across something I haven't expected.
The tutorial suggest to setup the test environment, starting with:
>>> from django.test.utils import setup_test_environment
I used the standard python shell throughout the whole tutorial without any problems, but now I got the following message:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/site-packages/django/test/__init__.py", line 5, in <module> from django.test.client import Client, RequestFactory File "/usr/lib/python2.7/site-packages/django/test/client.py", line 16, in <module> from django.contrib.auth import authenticate, login File "/usr/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 5, in <module> from django.middleware.csrf import rotate_token File "/usr/lib/python2.7/site-packages/django/middleware/csrf.py", line 16, in <module> from django.utils.cache import patch_vary_headers File "/usr/lib/python2.7/site-packages/django/utils/cache.py", line 26, in <module> from django.core.cache import get_cache File "/usr/lib/python2.7/site-packages/django/core/cache/__init__.py", line 70, in <module> if DEFAULT_CACHE_ALIAS not in settings.CACHES: File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__ self._setup(name) File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in _setup % (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Of course, this ought to be happen, since I have bypassed manage.py and thus the DJANGO_SETTINGS_MODULE environment variable wasn't set. Anyway, for django newbies who didn't follow your advise in part 1 of the tutorial this might come as an surprise.
1) Make the consequences of bypassing manage.py in part 1 of the tutorial more explicit ("XYZ won't work unless ...")
2) Some newbies might appreciate at this early point of the tutorial a deeper explanation of the DJANGO_SETTINGS_MODULE environment variable.
3) Repeat the advise to invoke the shell through manage.py in "Tutorial 5 / Test a view", to help lazy newbies like me :-)
Change History (14)
comment:1 Changed 8 months ago by st.sempert@…
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 8 months ago by st.sempert@…
- Cc st.sempert@… added
- Type changed from Uncategorized to Cleanup/optimization
comment:8 Changed 8 months ago by bussau
- Owner changed from nobody to bussau
- Status changed from new to assigned
comment:9 Changed 7 months ago by EvilDMP
- Cc EvilDMP added
- Keywords view", afraid-to-commit added; view" removed
comment:12 Changed 6 months ago by Tim Graham <timograham@…>
- Resolution set to fixed
- Status changed from assigned to closed