Kemical
Kemical

Reputation: 7

Template issue with django

I'm trying create a template with django but when I execute this sentences in the Python Shell

>>> from django.template import Template
>>>t = Template("My name is {{ my_name }}.")

It gives me this error

  Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    t = Template("Mi nombre es {{ mi_nombre }}.")
  File "django\template\base.py", line 123, in __init__
    if settings.TEMPLATE_DEBUG and origin is None:
  File "django\utils\functional.py", line 184, in inner
    self._setup()
  File "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.

Anybody know how i can fix this?

Upvotes: 0

Views: 143

Answers (1)

Nick Craig-Wood
Nick Craig-Wood

Reputation: 54117

Instead of running the python shell directly, use Django's wrapper.

cd to your project's directory, then run

python manage.py shell

This will give you an interactive shell where Django has been set up and has imported your settings.

There are other ways of achieving this but this should get you going.

Upvotes: 1

Related Questions