I am new to Django. When I tried creating a template, I got the following error. Please help.

>>> from django.template import Template, Context
>>> t = Template("The name is {{name}}")

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    t = Template("The name is {{name}}")
  File "C:\Python27\lib\site-packages\django\template\base.py", line 106, in __init__
    if settings.TEMPLATE_DEBUG and origin is None:
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 276, in __getattr__
    self._setup()
  File "C:\Python27\lib\site-packages\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.
Member Avatar for Enalicho

You need to set (or define, if you will) the environment variable DJANGO_SETTINGS_MODULE (;)) to the settings used in your django project. I suggest following the guide given here - https://docs.djangoproject.com/en/dev/intro/tutorial01/ since you're new to django.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.