开发者

Website with unique homepage layout in Django Templates

I am building a website with a unique homepage design (homepage has a different header and logo arrangement than all the other pages). However, I would like to have a base template which everything inherits from, to cut down on redundancies.

-base.html
  -basehome.html (inherits from base.html)
  -basesecond.html (inherits from base.html)
    -about.html (inherits from basesecond.html)
    -etc...

So base.html holds the html declaration and the structure. Basehome.html and basesecond.html contain the different header structures and the various other pages on the site inherit from basesecond.html.

So the problem I keep running into is, it seems like I need to put a block within a block to handle the body content which is obviously contained the (furthest) child template. As far as I know, Django does not let you do this.

base.html--

<html>
    <head>
        <title>Mysite</title>
     </head>
    <body id="{% block bodyholder %}{% endblock开发者_Go百科 %}">
        <div id="hd">{# start of hd #}
            {% block hd %}{% endblock %}
        </div>{# end of the hd #}
        <div id="bd">{# start of body #}
            {% block bd %}{% endblock %}
        </div>{# end of body #}             
    </body>
</html>

basehome.html--

{% extends "base.html" %}

{% block bodyholder %}bodyhome{% endblock %}

{% block hd %}
    big logo and wide header
{% endblock %}

{% block bd %}
    homepage body content
    this part works just like I want it to.
{% endblock %}

basesecond.html--

{% extends "base.html" %}

{% block bodyholder %}bodysecond{% endblock %}

{% block hd %}
    small logo and narrow header
{% endblock %}

{% block bd %}
    second page body content
    here is where I want to put extra blocks like
    {% block unique about page sidebar %}{% endblock %}
    but it breaks the template system
{% endblock %}

What is the best way to solve this problem?


If you're using exactly what you have shown you need to re-write a small portion:

instead of this

{% block unique about page sidebar %}{% endblock %}

replace it with this

{% block unique %}{% endblock %}
{% block about %}{% endblock %}
{% block page %}{% endblock %}
{% block sidebar %}{% endblock %}

Otherwise, everything looks like it should work. What error codes or behavior are you seeing that you aren't expecting?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜