How to call or include one file of code into many files dynamically in django ?


Here is the solution:

first of all create any file that you are going to use/extend in other files. here is some example code, we give it a named base.html. 

This file will be extend many other files as an example:

<p>Hello From the Top</p>

{% block content %}
{% endblock %}

<p>Hello from the bottom</p>

Now you can easily call this file of code in any other file of your project. For example I am going to create another file called home.html

First call your base file:
{% extends ‘base.html’ %}

Then write your home.html file code into the block content.

{% block content %}
<h1>Home Page</h1>
{% endblock %}

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.