如何使用标记和过滤器将页脚从index.html显示到所有html页面?

如何使用标记和过滤器将页脚从index.html显示到所有html页面?,html,django,django-rest-framework,django-templates,Html,Django,Django Rest Framework,Django Templates,如果我有index.html,并且它包含许多插件,比如搜索框、帖子、评论区等等。。。我只想利用页脚部分并使用标记和过滤器将其添加到我的所有html页面中,以便将来在所有html页面中轻松编辑,我可以这样做吗 这是index.html中的我的页脚代码: <footer style="margin:auto" class="py-5 bg-dark h-50 d-inline-block w-100 p-3"> <div class=&quo

如果我有index.html,并且它包含许多插件,比如搜索框、帖子、评论区等等。。。我只想利用页脚部分并使用标记和过滤器将其添加到我的所有html页面中,以便将来在所有html页面中轻松编辑,我可以这样做吗

这是index.html中的我的页脚代码:

<footer style="margin:auto" class="py-5 bg-dark h-50 d-inline-block w-100 p-3">
<div class="container">

<div class="text-center mt-4">
          
     <a href="/Privacy_Policy" style="margin:5px;width:140px" role="presentation" type="button" class="btn btn-secondary btn-lg">Privcy Policy</a>
     
     <a href="/request_apps/" style="margin:5px;width:140px" role="presentation" type="button" class="btn btn-secondary btn-lg">Request apps</a> 
     
     <a href="/our_Mission" style="margin:5px;width:140px" role="presentation" type="button" class="btn btn-secondary btn-lg">Our Mission</a>
  
     <a href="/Contact_US" style="margin:5px;width:140px" role="presentation" type="button" class="btn btn-secondary btn-lg">Contact us</a>
     
      <a href="/About_Me" style="margin:5px;width:140px" role="presentation" type="button" class="btn btn-secondary btn-lg">About us</a>

</div>

<!-- copyright -->
  <p style="font-family:monospace;font-size:18px" class="m-0 text-center text-white" >Copyright 2019-2020 SoftDLR.com All Rights Reserved. </p>
</div>
<!-- /.container -->

版权所有2019-2020 SoftDLR.com保留所有权利


您可能希望有一个包含多个块的基本HTML文件,并从中创建其他扩展页:


* {
字号:14 ;;
}
{%block head%}
{%endblock%}
{%block body%}
{%endblock%}
...
然后,您将创建如下所示的所有文件:

manage.py
templates
----base.html
----snippets
    ----base_css.html
    ----header.html
    ----footer.html
    ----other_snippet.html
    ----another_snippet.html
    ----and_another_snippet.html

{%extends“base.html”%}
{%block head%}
div{
保证金:0;
}
{%endblock%}
{%block body%}
页脚应添加在此段落之后

{%endblock%}

使用块扩展的思想是,每当您请求
page.html
,它都会将
base.html
与您在
page.html
上创建的块定义一起使用。如果未定义块,它将不会在最终html上呈现。

您可能希望有一个包含多个块的基本html文件,并从中创建其他扩展页:


* {
字号:14 ;;
}
{%block head%}
{%endblock%}
{%block body%}
{%endblock%}
...
然后,您将创建如下所示的所有文件:

manage.py
templates
----base.html
----snippets
    ----base_css.html
    ----header.html
    ----footer.html
    ----other_snippet.html
    ----another_snippet.html
    ----and_another_snippet.html

{%extends“base.html”%}
{%block head%}
div{
保证金:0;
}
{%endblock%}
{%block body%}
页脚应添加在此段落之后

{%endblock%}

使用块扩展的思想是,每当您请求
page.html
,它都会将
base.html
与您在
page.html
上创建的块定义一起使用。如果一个块没有定义,它就不会在最终的html上呈现。

上面推荐的@João Haas方法非常有效,我个人使用另一种方法,尽管我不认为这两种方法在技术上都比另一种好,那就是将页脚设置为它自己的独立片段。我个人认为这是干净的期待阅读和编辑

<!-- base.html -->
    <html>
      <head>
          <!-- stuff you want every page to have on the head -->
          <!-- head block for extending -->
          {% block head %}
          {% endblock %}
        </head>
        <body>
          <!-- body block for extending -->
          {% include 'snippets/base_css.html' %}
          {% include 'snippets/header.html' %}
          {% block body %}
          {% endblock %}
          <!-- your footer html -->
          {% include 'snippets/footer.html' %}
      </html>

<!-- snippets/footer.html -->
<footer class="container">
    <p> footer info </p>
</footer>

<!-- snippets/header.html -->
<div class="container">
    <p>Header info</p>
</div>

老实说,越是开心,我就越是疯狂地使用这些东西。当代码变得越来越复杂时,它们使生活变得更加轻松。

上面@João Haas推荐的方法非常有效,我个人使用的另一种方法是,尽管我认为两者在技术上都不比另一种好,那就是将页脚设置为自己的独立片段。我个人认为这是干净的期待阅读和编辑

<!-- base.html -->
    <html>
      <head>
          <!-- stuff you want every page to have on the head -->
          <!-- head block for extending -->
          {% block head %}
          {% endblock %}
        </head>
        <body>
          <!-- body block for extending -->
          {% include 'snippets/base_css.html' %}
          {% include 'snippets/header.html' %}
          {% block body %}
          {% endblock %}
          <!-- your footer html -->
          {% include 'snippets/footer.html' %}
      </html>

<!-- snippets/footer.html -->
<footer class="container">
    <p> footer info </p>
</footer>

<!-- snippets/header.html -->
<div class="container">
    <p>Header info</p>
</div>


老实说,越是开心,我就越是疯狂地使用这些东西。当代码变得越来越复杂时,它们使生活变得简单了一百万倍。

您是否使用扩展用于其他视图的基本HTML模板?不,我不@Ryant这是您需要的@João Haas answer向您展示了如何使用。感谢您的时间。您是否使用扩展用于其他视图的基本HTML模板?不,我不@Ryant这是您需要的@乔·哈斯的回答告诉你怎么做。谢谢你的时间,这是一个鲁奥特兄弟,,,非常感谢,,,我发现布什·芒彻的方式比你的方式简单,但你的方式非常有用,真的会帮我很多忙,谢谢你,事实上,布什的方式可能会更好,这取决于项目的规模,这是一个鲁奥特兄弟,,,非常感谢,,,我发现Bush Muncher的方法比你的方法简单,但是你的方法非常有用,真的会对我有很大帮助,谢谢你,实际上Bush的方法可能会根据项目的大小更好谢谢兄弟,真的,只需问几个问题,我必须先创建footer.html,然后添加我的样式,然后使用{%include'代码段/footer.html%}在任何一页,对吗?不用担心,伙计,我会在上面的回答中添加帮助描述这个过程谢谢你救了我,我在等你谢谢,不用担心,伙计,如果答案对你有用,永远记得你可以投票接受,如果没有,让我知道我能做些什么来帮助更多你好,你能帮我吗[非常感谢兄弟,请回答几个问题,我必须先创建footer.html,然后添加我的样式,然后使用{%include'snippets/footer.html%}在任何一页,对吗?不用担心,伙计,我会在上面的回答中添加帮助描述这个过程谢谢你救了我,我在等你谢谢,不用担心,伙计,如果答案对你有用,永远记得你可以投票接受,如果没有,让我知道我能做些什么来帮助更多你好,你能帮我吗[