此代码(更准确地说是此代码的第一行)
from django.template import Template
from django.template import Context
from django.conf import settings
settings.configure()
t = Template('My name is {{ my_name }}.')
c = Context({'my_name': 'Foo Bar'})
t.render(c)
给了我这个错误堆栈:
pydev debugger: starting
Traceback (most recent call last):
File "C:\Program Files\Brainwy\LiClipse 0.9.7\plugins\org.python.pydev_3.3.3.201401272005\pysrc\pydevd.py", line 1738, in <module>
debugger.run(setup['file'], None, None)
File "C:\Program Files\Brainwy\LiClipse 0.9.7\plugins\org.python.pydev_3.3.3.201401272005\pysrc\pydevd.py", line 1355, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\Brainwy\LiClipse 0.9.7\plugins\org.python.pydev_3.3.3.201401272005\pysrc\_pydev_execfile.py", line 38, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script
File "C:\WORKSPACE\Liclipse\test\src\test.py", line 1, in <module>
from django.template import Template
File "C:\win64app\Django\django\template\__init__.py", line 53, in <module>
from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END,
File "C:\win64app\Django\django\template\base.py", line 268
except TemplateSyntaxError, e:
^
SyntaxError: invalid syntax
我的PYTHONPATH变量等于:
C:\win64app\Django\;C:\win64app\python33\Lib;C:\win64app\python33\DLLs
每个文件夹都存在。而django.template显然是在那里找到的。
有什么想法吗?
答案 0 :(得分:2)
你正在使用旧版本的Django。只有版本1.6以上版本与Python 3兼容。