django cookiecutter扩展base.html抹掉我的网页 [英] django cookiecutter extending base.html wipes out my web page

查看:128
本文介绍了django cookiecutter扩展base.html抹掉我的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,我于2017年6月开始使用刚刚安装的cookiecutter。当时,就django而言,我是一个绝对的初学者。 (到目前为止,我已经有了一些进步,但稍微有些进步。)

I am working on a project that I started in June 2017 with the cookiecutter I had just installed. At the time, with respect to django, I was an absolute beginner. (I am a bit more advanced by now, but just a bit.)

Cookiecutter将base.html放在templates目录中(app子目录的上一级)。

Cookiecutter put a base.html in the templates directory (one level above the app subdirectories).

对于模型行列表,我有一个模板可以自行工作,如下所示:

For a list of model rows, I have a template that works all by itself, as follows:

{% if brand_list %}
    <ul>
    {% for brand in brand_list %}
        <li><a href="/brands/{{ brand.id }}/">{{ brand.cTitle }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No brands are available.</p>
{% endif %}

但是,如果我把它放在顶部,没有得到列表::

But, if I put this at the top, I do not get the list::

{% extends "base.html" %}

我取而代之的是项目根网页,它位于/./

What I get instead is the project root webpage, the one at /.

这个base.html的问题,还是别的什么?

Is this base.html the problem, or something else?

推荐答案

您的 base.html mus有一对模板标签,如下所示:

Your base.html mus have a pair of template tags like this:

{% block content %}{% endblock %}

base.html 继承的模板会填充这些标签之间的内容:

The template that inherits from base.html populates the content between those tags:

因此,在您继承的模板中,您将

So in your inherited template you put

{% extends "base.html" %}

{% block content %} 

    {% if brand_list %}
        <ul>
        {% for brand in brand_list %}
            <li><a href="/brands/{{ brand.id }}/">{{ brand.cTitle }}</a></li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No brands are available.</p>
    {% endif %}

{% endblock %}

这篇关于django cookiecutter扩展base.html抹掉我的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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