Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you insert a template into another template?

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?

like image 617
WindowsMaker Avatar asked Jun 11 '12 18:06

WindowsMaker


People also ask

Which tag is used to load another template in current template file?

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.

How do you add a HTML template?

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.

What does {% include %} do?

Q13:-What does {% include %} does? It will include another template. It will include content from another template having the same templates defined.


1 Answers

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> 
like image 57
Simeon Visser Avatar answered Oct 07 '22 14:10

Simeon Visser