Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
379 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...