Django模板继承会导致总线错误 [英] Django Template inheritance causes a bus error

查看:219
本文介绍了Django模板继承会导致总线错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Django模板中的多层次结构中工作,因此我需要一个主基础模板( base / base.html ),我有几个主从 base / base_twocol.html 扩展的模板。然后我有模板从这些模板扩展,例如 base / base_twocol_SECTION



然后我需要相同的模板集合将处理另一个站点,但是从这些模板扩展,例如 another_site / base.html another_site / base_twocol。 html another_site / base_twocol_SECTION.html



目标是拥有一个主人



所以我有这样的一些:

  templates / 
base /
base.html
base_twocol.html // extends base.html
base_twocol_SECTION.html // extends base_twocol.html
another_site /
base.html // extends base / base.html
base_twocol.html // extends base / base_twocol.html
base_twocol_SECTION.html // extends base / base_twocol_SECTION.html
super_cool_ site /
base.html // extends base / base.html
base_twocol.html // extends base / base_twocol.html
base_twocol_SECTION.html // extends base / base_twocol_SECTION.html

我创建了我的 another_site / base.html ,并使用语法 {%extendsbase.html%}



然而,当我运行服务器时,我从浏览器中得到一个没有数据收到错误,从控制台收到总线错误。

解决方案

总线错误正在由文件的命名来表示,因为有两个同名的模板,其中一个模板试图从另一个扩展。



another_site / base.html 中,我有 {%extendsbase.html%} ,但这文件也被称为 base.html



所以基本上,我不能有一个名为X的tempalte,另一个te mpalte称为X,它扩展了模板X.也许我的问题不是很正确,这就是为什么没有收到。



子模板需要有一个独一无二的名字。我做了所有的模板文件,现在它的工作正常。


I'm working in a multisite hierarchy in a Django template, whereby I need a master base template (base/base.html), for which I have several master templates extending from, such as base/base_twocol.html. And then I have templates that extend from those templates, such as base/base_twocol_SECTION.

Then I need to have the same set of templates, which will deal with another site, but extending from those templates, such as another_site/base.html, another_site/base_twocol.html, another_site/base_twocol_SECTION.html.

The goal is to have a master set of templates that can be overridden for each site.

So I have something like this:

templates/
    base/
        base.html 
        base_twocol.html           //extends base.html
        base_twocol_SECTION.html   // extends base_twocol.html
    another_site/
        base.html                  //extends base/base.html
        base_twocol.html           //extends base/base_twocol.html
        base_twocol_SECTION.html   //extends base/base_twocol_SECTION.html
    super_cool_site/
        base.html                  //extends base/base.html
        base_twocol.html           //extends base/base_twocol.html
        base_twocol_SECTION.html   //extends base/base_twocol_SECTION.html

I've created my another_site/base.html, and used the syntax {% extends "base.html" %}

However when I run the server, I get a "No data received error" from the browser and "Bus error" from the console.

解决方案

The bus error is being manifested by the naming of the files, because there are two templates of the same name, with one of them trying to extend from the other.

In another_site/base.html, I have {% extends "base.html" %}, but this file is also called base.html.

So basically, I can't have a tempalte called X, and another tempalte called X which extends template X. Perhaps my question wasn't phrased quite right which is why this wasn't picked up on.

The child template needs to have a unique name. I did this for all of my template files and now it works fine.

这篇关于Django模板继承会导致总线错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆