python - Google App Engine 中的 Django 模板语法错误

标签 python google-app-engine django-templates

我尝试在本地主机上启动我的 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/

相关文章:

django - Django模板:字典键的值,其中带有空格

django-templates - LogoutView 中的模板名称不适用于 django2.1 python3.7

python - python中的字符串替换性能

python - 单击 "play"时如何清除游戏屏幕并移动到新场景

java - 为什么要在 App Engine 上设置系统属性(例如 java.vm.specation.version)?

java - 如何在 1 秒内从 GAE 数据存储中检索大量(>2000)实体?

google-app-engine - 只有一个实体的跨组交易错误

django - 如何在模板中显示 Django 表单字段的值?

python - 从 WebDriver 元素检索属性

python - 如何从 pandas 数据框中进行循环抓取