what is {% block content %} and {% endblock content %} for in Django?












-2














so I just started reading a book on Django (for beginners) and I came across the following code snipet:



<header>

<a href="{% url 'home' %}">Home</a> | <a href="{% url 'about' %}">About</a>

</header>

{% block content %}
{% endblock content %}


Could anyone possibly explain to me what is the use of {% block content %} and {% endblock content %}? Thank you very much in advance!










share|improve this question


















  • 2




    I suggest you to keep reading. Seriously, this question is too broad for StackOverflow format but it should be explained later in that book. Alternatively you can refer to Django docs
    – Selcuk
    Nov 19 at 22:37












  • docs.djangoproject.com/en/2.1/ref/templates/builtins/#block
    – 9769953
    Nov 19 at 22:38
















-2














so I just started reading a book on Django (for beginners) and I came across the following code snipet:



<header>

<a href="{% url 'home' %}">Home</a> | <a href="{% url 'about' %}">About</a>

</header>

{% block content %}
{% endblock content %}


Could anyone possibly explain to me what is the use of {% block content %} and {% endblock content %}? Thank you very much in advance!










share|improve this question


















  • 2




    I suggest you to keep reading. Seriously, this question is too broad for StackOverflow format but it should be explained later in that book. Alternatively you can refer to Django docs
    – Selcuk
    Nov 19 at 22:37












  • docs.djangoproject.com/en/2.1/ref/templates/builtins/#block
    – 9769953
    Nov 19 at 22:38














-2












-2








-2







so I just started reading a book on Django (for beginners) and I came across the following code snipet:



<header>

<a href="{% url 'home' %}">Home</a> | <a href="{% url 'about' %}">About</a>

</header>

{% block content %}
{% endblock content %}


Could anyone possibly explain to me what is the use of {% block content %} and {% endblock content %}? Thank you very much in advance!










share|improve this question













so I just started reading a book on Django (for beginners) and I came across the following code snipet:



<header>

<a href="{% url 'home' %}">Home</a> | <a href="{% url 'about' %}">About</a>

</header>

{% block content %}
{% endblock content %}


Could anyone possibly explain to me what is the use of {% block content %} and {% endblock content %}? Thank you very much in advance!







python django






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 22:32









Fozoro

1,164720




1,164720








  • 2




    I suggest you to keep reading. Seriously, this question is too broad for StackOverflow format but it should be explained later in that book. Alternatively you can refer to Django docs
    – Selcuk
    Nov 19 at 22:37












  • docs.djangoproject.com/en/2.1/ref/templates/builtins/#block
    – 9769953
    Nov 19 at 22:38














  • 2




    I suggest you to keep reading. Seriously, this question is too broad for StackOverflow format but it should be explained later in that book. Alternatively you can refer to Django docs
    – Selcuk
    Nov 19 at 22:37












  • docs.djangoproject.com/en/2.1/ref/templates/builtins/#block
    – 9769953
    Nov 19 at 22:38








2




2




I suggest you to keep reading. Seriously, this question is too broad for StackOverflow format but it should be explained later in that book. Alternatively you can refer to Django docs
– Selcuk
Nov 19 at 22:37






I suggest you to keep reading. Seriously, this question is too broad for StackOverflow format but it should be explained later in that book. Alternatively you can refer to Django docs
– Selcuk
Nov 19 at 22:37














docs.djangoproject.com/en/2.1/ref/templates/builtins/#block
– 9769953
Nov 19 at 22:38




docs.djangoproject.com/en/2.1/ref/templates/builtins/#block
– 9769953
Nov 19 at 22:38












2 Answers
2






active

oldest

votes


















2














That's where the power of the templates comes from in a sense.



You can create a hierarchy of templates so start with base.html which might be like you've got above;



<body>
{% block content %}
{% endblock content %}
</body>


Then you can create any other template, home.html for example, and do something like;



{% extends "base.html" %}

{% block content %}
<h1>Welcome</h1>
<p>This is the home page</p>
{% endblock content %}


Then you'd reference home.html in django and it'd include the markup from base.py with the content defined in home.html.



That's the basics, but if you put some templates together using blocks you'll pick it up.






share|improve this answer





























    2














    block is used for overriding specific parts of a template.



    In your case, you have a block named content and this is supposed to be overridden by children that inherit from this template.



    From the examples at The Django Docs



    Template to be extended, named base.html



    <head>
    <link rel="stylesheet" href="style.css">
    <title>{% block title %}My amazing site{% endblock %}</title>
    </head>


    Overriding Child template



    {% extends "base.html" %}

    {% block title %}My amazing blog{% endblock %}


    "My amazing site" will be overriden by the child and then display "My amazing blog"






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383602%2fwhat-is-block-content-and-endblock-content-for-in-django%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      That's where the power of the templates comes from in a sense.



      You can create a hierarchy of templates so start with base.html which might be like you've got above;



      <body>
      {% block content %}
      {% endblock content %}
      </body>


      Then you can create any other template, home.html for example, and do something like;



      {% extends "base.html" %}

      {% block content %}
      <h1>Welcome</h1>
      <p>This is the home page</p>
      {% endblock content %}


      Then you'd reference home.html in django and it'd include the markup from base.py with the content defined in home.html.



      That's the basics, but if you put some templates together using blocks you'll pick it up.






      share|improve this answer


























        2














        That's where the power of the templates comes from in a sense.



        You can create a hierarchy of templates so start with base.html which might be like you've got above;



        <body>
        {% block content %}
        {% endblock content %}
        </body>


        Then you can create any other template, home.html for example, and do something like;



        {% extends "base.html" %}

        {% block content %}
        <h1>Welcome</h1>
        <p>This is the home page</p>
        {% endblock content %}


        Then you'd reference home.html in django and it'd include the markup from base.py with the content defined in home.html.



        That's the basics, but if you put some templates together using blocks you'll pick it up.






        share|improve this answer
























          2












          2








          2






          That's where the power of the templates comes from in a sense.



          You can create a hierarchy of templates so start with base.html which might be like you've got above;



          <body>
          {% block content %}
          {% endblock content %}
          </body>


          Then you can create any other template, home.html for example, and do something like;



          {% extends "base.html" %}

          {% block content %}
          <h1>Welcome</h1>
          <p>This is the home page</p>
          {% endblock content %}


          Then you'd reference home.html in django and it'd include the markup from base.py with the content defined in home.html.



          That's the basics, but if you put some templates together using blocks you'll pick it up.






          share|improve this answer












          That's where the power of the templates comes from in a sense.



          You can create a hierarchy of templates so start with base.html which might be like you've got above;



          <body>
          {% block content %}
          {% endblock content %}
          </body>


          Then you can create any other template, home.html for example, and do something like;



          {% extends "base.html" %}

          {% block content %}
          <h1>Welcome</h1>
          <p>This is the home page</p>
          {% endblock content %}


          Then you'd reference home.html in django and it'd include the markup from base.py with the content defined in home.html.



          That's the basics, but if you put some templates together using blocks you'll pick it up.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 22:38









          markwalker_

          4,46553574




          4,46553574

























              2














              block is used for overriding specific parts of a template.



              In your case, you have a block named content and this is supposed to be overridden by children that inherit from this template.



              From the examples at The Django Docs



              Template to be extended, named base.html



              <head>
              <link rel="stylesheet" href="style.css">
              <title>{% block title %}My amazing site{% endblock %}</title>
              </head>


              Overriding Child template



              {% extends "base.html" %}

              {% block title %}My amazing blog{% endblock %}


              "My amazing site" will be overriden by the child and then display "My amazing blog"






              share|improve this answer


























                2














                block is used for overriding specific parts of a template.



                In your case, you have a block named content and this is supposed to be overridden by children that inherit from this template.



                From the examples at The Django Docs



                Template to be extended, named base.html



                <head>
                <link rel="stylesheet" href="style.css">
                <title>{% block title %}My amazing site{% endblock %}</title>
                </head>


                Overriding Child template



                {% extends "base.html" %}

                {% block title %}My amazing blog{% endblock %}


                "My amazing site" will be overriden by the child and then display "My amazing blog"






                share|improve this answer
























                  2












                  2








                  2






                  block is used for overriding specific parts of a template.



                  In your case, you have a block named content and this is supposed to be overridden by children that inherit from this template.



                  From the examples at The Django Docs



                  Template to be extended, named base.html



                  <head>
                  <link rel="stylesheet" href="style.css">
                  <title>{% block title %}My amazing site{% endblock %}</title>
                  </head>


                  Overriding Child template



                  {% extends "base.html" %}

                  {% block title %}My amazing blog{% endblock %}


                  "My amazing site" will be overriden by the child and then display "My amazing blog"






                  share|improve this answer












                  block is used for overriding specific parts of a template.



                  In your case, you have a block named content and this is supposed to be overridden by children that inherit from this template.



                  From the examples at The Django Docs



                  Template to be extended, named base.html



                  <head>
                  <link rel="stylesheet" href="style.css">
                  <title>{% block title %}My amazing site{% endblock %}</title>
                  </head>


                  Overriding Child template



                  {% extends "base.html" %}

                  {% block title %}My amazing blog{% endblock %}


                  "My amazing site" will be overriden by the child and then display "My amazing blog"







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 at 22:38









                  Cup of Java

                  68521028




                  68521028






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383602%2fwhat-is-block-content-and-endblock-content-for-in-django%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                      Alcedinidae

                      Can an atomic nucleus contain both particles and antiparticles? [duplicate]