Python中使用template模板创建template时,报错,
原因以及修改方法:
1**.必须是在一个django 项目目录下使用python manage.py shell
而不能随便在某一个目录下使用ipython 或者python 进入shell界面。**
wang@ubuntu:/home/wpython/blog$ python manage.py shell
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
Type “copyright”, “credits” or “license” for more information.
IPython 2.4.1 – An enhanced Interactive Python.
? -> Introduction and overview of IPython’s features.
%quickref -> Quick reference.
help -> Python’s own help system.
object? -> Details about ‘object’, use ‘object??’ for extra details.
In [1]: from django import template
In [2]: t=template.Template(‘my name is {{name}}’)
In [3]: c = template.Context({‘name’:’wang’})
In [4]: t.render(c)
Out[4]: ‘my name is wang’