Error when using django.template
django, django-models, django-templates
Solution
You can't access and run django projects from python shell. Django doesn't know what project you want to work on.
You have to do one of these things:
1. python manage.py shell
2. Set DJANGO_SETTINGS_MODULE environment variable in your OS to mysite.settings
3. Use setup_environ in the python interpreter:
from django.core.management import setup_environ
from mysite import settings
setup_environ(settings)
The first one is easiest and best method. Run your code in the django shell.
Problem
I'm a beginner in django and I got a lot of errors when using template module from django. The following works from the python shell: ``` from django import template t = template.Template('My name is {{ name }}.') ``` When i use this code , i get the following error: ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/site-packages/django/template/base.py", line 123, in __init__ if settings.TEMPLATE_DEBUG and origin is None: 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 TEMPLATE_DEBUG,but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. ``` Dose anyone have an idea about this error?