Django Template inheritance causes a bus error

筅森魡賤 提交于 2019-12-11 01:55:50

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11900187/django-template-inheritance-causes-a-bus-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!