2

我在 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, 并使用了语法{% extends "base.html" %}

但是,当我运行服务器时,我从浏览器收到“未收到数据错误”,从控制台收到“总线错误”。

4

2 回答 2

2

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

another_site/base.html中,我有{% extends "base.html" %},但这个文件也称为base.html

所以基本上,我不能有一个名为 X 的模板,以及另一个名为 X 的模板,它扩展了模板 X。也许我的问题措辞不太正确,这就是为什么没有被采纳的原因。

子模板需要有一个唯一的名称。我对所有模板文件都这样做了,现在它工作正常。

于 2012-08-14T15:28:54.623 回答
1

From a thread in the django-users group:

A bus error occurs due to unaligned memory access, or access to a non existent memory address. In the absence of an actual bug (which others would see), this clearly indicates that one or another of the C libraries used by python conflicts with it.

This could happen if you compiled a C library to use with python, like one of the many python packages that consist of a small C library (mysql and postgresql DB adaptors, PIL, many others), and use it with a different python than it was compiled against.

This is almost certainly nothing to do with your template inheritance. Check your Python and Django installation, reinstalling if necessary. Please also provide more details about your environment and, as Jonas says, the full stack trace.

于 2012-08-10T13:16:37.153 回答