I have a very basic template (basic_template.html), and want to fill in the with data formatted using another partial template. The basic_template.html might contain several things formatted using the partial template.
How should I structure the code in views.py?
The reason I am doing this is that later on the will be filled using Ajax. Am I doing this right?
include tag loads a template and renders it with the current context. This is a way of “including” other templates within a template. The template name can either be a variable or a hard-coded (quoted) string, in either single or double quotes.
You can use the <template> tag if you have some HTML code you want to use over and over again, but not until you ask for it. To do this without the <template> tag, you have to create the HTML code with JavaScript to prevent the browser from rendering the code.
Q13:-What does {% include %} does? It will include another template. It will include content from another template having the same templates defined.
You can do:
<div class="basic"> {% include "main/includes/subtemplate.html" %} </div>
where subtemplate.html
is another Django template. In this subtemplate.html
you can put the HTML that would be obtained with Ajax.
You can also include the template multiple times:
<div class="basic"> {% for item in items %} {% include "main/includes/subtemplate.html" %} {% endfor %} </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With