創建模板我學習Django
,我試圖創建一個模板是這樣的:在Django/Python的
>>> weekend = True
>>> from django.template import Template, Context
>>> template_string = """
{% if weekend %}
<p> This is a weekend </p>
{% endif %}
"""
>>> t = Template(template_string)
我得到這個下面的錯誤。我錯過了什麼嗎?
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
t = Template(template_string)
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.
謝謝!
「ImportError:無法導入設置,因爲環境變量DJANGO_SETTINGS_MODULE未定義。」似乎很清楚。你是否遵循官方的Django教程?如果不是,你遵循什麼教程? – 2011-04-21 11:16:20
是的,我正在使用'djangobook.com'的書。對不起這是我的錯。錯過了。而是剛剛開始'IDLE' – bdhar 2011-04-21 11:19:18