Django learning

52 views
Skip to first unread message

lovetoprogram

unread,
Jun 22, 2012, 2:15:53 AM6/22/12
to Django users
I tried to do this according the tutorial.
>>> from django import template
>>> t = template.Template('My name is {{ name }}.')
>>> c = template.Context({'name': 'Adrian'})
>>> print t.render(c)
My name is Adrian.
>>> c = template.Context({'name': 'Fred'})
>>> print t.render(c)
My name is Fred.

But I got this error
>>> t = template.Template('My name is {{ name }}.')

Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
t = template.Template('My name is {{ name }}.')
File "C:\Python27\lib\site-packages\django\template\base.py", line
123, in __init__
if settings.TEMPLATE_DEBUG and origin is None:
File "C:\Python27\lib\site-packages\django\utils\functional.py",
line 184, in inner
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.

Any help

Cheers

Tomás Garzón Hervás

unread,
Jun 22, 2012, 3:24:48 AM6/22/12
to django...@googlegroups.com
Hi, you have to indicate where is the settings file to django. You can use the environment variable DJANGO_SETTINGS_MODULE.
 More info:

Daniel Roseman

unread,
Jun 22, 2012, 10:19:02 AM6/22/12
to django...@googlegroups.com
You're supposed to load the shell with `./manage.py shell` rather than going directly into Python. That is explained in the tutorial.
--
DR. 

Kurtis Mullins

unread,
Jun 22, 2012, 10:55:24 AM6/22/12
to django...@googlegroups.com
You're supposed to load the shell with `./manage.py shell` rather than going directly into Python. That is explained in the tutorial.
--
DR. 

+1 -- However, I recommend installing the package "ipython" when using the Django Shell. For example, run: "pip install ipython". 

This will give you auto-completion. So if you started typing something like "models." and hit tab, it'd show you all of the available methods and classes you can use.
Reply all
Reply to author
Forward
0 new messages