我尝试在本地主机上启动我的 Google App Engine 应用程序,但遇到了 Django 错误,我陷入困境。
“TemplateSyntaxError:模板'base/_base.html'无法扩展,因为它不存在”
我将模板放在/templates 中,然后将 _base.html 和 index.html 放在/templates/base 中。谢谢! 埃米尔@proudn00b.com
错误:
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 511, in __call__
handler.get(*groups)
File "/Users/emilepetrone/code/thebuswheel/main.py", line 65, in get
outstr = template.render(temp, { 'path': path })
….
…..
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django/django/template/loader_tags.py", line 58, in get_parent
raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
TemplateSyntaxError: Template 'base/_base.html' cannot be extended, because it doesn't exist
引用:
def get(自身):
path = self.request.path
temp = os.path.join(
os.path.dirname(__file__),
'templates' + path)
if not os.path.isfile(temp):
temp = os.path.join(
os.path.dirname(__file__),
'templates/base/index.html')
outstr = template.render(temp, { 'path': path })
self.response.out.write(outstr)
最佳答案
您可以仔细检查的另一件事是确保 TEMPLATE_DIRS 设置中的路径之一指向模板的根目录。
还要确保它是设置中的完整绝对路径,而不是相对于项目的路径。
关于python - Google App Engine 中的 Django 模板语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3516918/