第一次用Django 根据网上资料安装后 简单找了个例子
from django.template import Template,Context from django.conf import settings settings.configure() t = Template('my name is {{ name }}.') c = Context({'name':'nowamagic'}) print t.render(c)
然后运行就报错没有DjangoTemplates 后台配置,是什么问题造成的呢?
Traceback (most recent call last): File "D:/PythonTest/testing/test04.py", line 7, in <module> t = Template('my name is {{ name }}.') File "E:\Python27\lib\site-packages\django\template\base.py", line 184, in __init__ engine = Engine.get_default() File "E:\Python27\lib\site-packages\django\utils\lru_cache.py", line 124, in wrapper result = user_function(*args, **kwds) File "E:\Python27\lib\site-packages\django\template\engine.py", line 83, in get_default "No DjangoTemplates backend is configured.") django.core.exceptions.ImproperlyConfigured: No DjangoTemplates backend is configured.
你不能在python直接跑。需要启动django的shell,在跑你的脚本:
python manage.py shell
楼上正解!