What is include and extends in django?

0
What is include and extends in Django?

Include is used to call the common content in the Django application, it is used to include the content of the calling page to the main page.

{%     include 'appname/pagename.html'  %}

How to use include tag in page template:-

step1st:-   create an app

step2nd:  create a folder under app with name templates/appname

step3rd:-   create filename under templates/appname using header.html

step4th:-  call header.html file under the main file

          {%     include 'appname/header.html'  %}


header.html


<h1>sssssss</h1>

another page polls.html

{%    include  'polls/header.html'  %}







................................................................................................................................

extends:-  it is used to extend the features of the parent template from the child template.

It provides a master-child approach that means base.html is the master page that will be used to render the content of the child page.




  {%     extends 'appname/header.html'  %}



<html>
  <head>
  </head>

  <body>
  <header style="background-color: orange;">
  <h1>Welcome</h1>
  </header>
  <section style="height:500px;">
 
    {% block content %}

           {% endblock %}
  </section>
   

     <footer style="background-color:orange;">
      footer
     </footer>
   </body>
</html>

child.html

{% extends 'polls/base.html' %}

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



Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)