Search This Blog

What is include and extends in Django?

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


How we use include a 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.


  {%     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

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post