我有一个与Django建立的基本网站,并且一直在关注Sentdex教程。我无法弄清楚如何在Bootstrap"关于"部分中包含博客文章(我认为这是博客。基本上,我希望博客文章(从数据库派生)出现在Bootstrap中的"大约"部分,而不是在底部或单独的页面中。
。我有一个'withme'应用程序(主网站),其中包含 home.html
{%extends "aboutme/header.html" %}
{%block content%}
<p>Welcome to this "about" page that is all about the website:
{%include "aboutme/includes/mysnippet.html"%}
{% endblock %}
{%block blogcontent%}
{% endblock %}
..和a header.html 包含Bootstrap网站本身的整个index.html。以下是 bootstrap Webt的关于/博客部分的大约部分,其中包括django templating Logic(block content)
<!-- About Section (Blog)-->
<section class="bg-primary text-white mb-0" id="about">
<div class="container">
<h2 class="text-center text-uppercase text-white">Blog</h2>
<hr class="star-light mb-5">
<div class="row">
<div class="col-lg-4 ml-auto">
<p class="lead">This is the blog section</p>
{%block blogcontent%}
{%endblock %}
</div>
<div class="col-lg-4 mr-auto">
<p class="lead">The blogs outlined in the models section and stored in the database, are going to be displayed here.</p>
</div>
</div>
<div class="text-center mt-4">
<a class="btn btn-xl btn-outline-light" href="#">
<i class="fa fa-download mr-2"></i>
Download Now!
</a>
</div>
</div>
</section>
最后,我还有另一个名为"博客"的应用程序,该应用程序的模板/博客目录内部:post.html和blog.html
blog.html
{% extends "aboutme/header.html" %}
{%block content %}
{% for post in object_list %}
<h5>{{post.date|date:"Y-m-d"}}<a href="/blog/{{post.id}}">{{post.title}}</a></h5>
{% endfor %}
{% endblock %}
post.html
{% extends "aboutme/header.html" %}
{%block content %}
<h3>{{post.title}}</h3>
<h6>on{{post.date}}</h6>
{{post.body|safe|linebreaks}}
{% endblock %}
当我键入http://127.0.0.1:8000/blog时...博客帖子出现在页面底部,或者在{%block content%} {%endblock%}的地方(但是它似乎只在页面的底部工作)。
如何使博客文章出现在Bootstrap网站的"关于我"部分?
我也很喜欢关于Home.html页面的确切解释,并且可以命名任何东西,或者必须是"家"。是否在其中定义了所有内容,以及它如何工作?
编辑/设计您的代码:
html索引或aboutme/header.html
// codes here
{% block blogcontent %}
{% include 'path/blog.html' %}
{% enblock %}
// codes here
{% block postcontent %}
{% include 'path/post.html' %}
{% enblock %}
<!-- end -->
当您致电127.0.0.1:8000时,一切都将在那里提供。对于其他链接,如果您不想显示博客或帖子块,只需使用{%block blogcontent%} {%endBlock%} {%block postcontent%} {%endblock%} whitout