开发者

Can a django template be referenced from within a loop on another template?

开发者 https://www.devze.com 2023-02-15 16:07 出处:网络
I have a django template which loops over many notes/comments.As a simplified exampl开发者_如何学编程e take this.

I have a django template which loops over many notes/comments. As a simplified exampl开发者_如何学编程e take this.

{% for note in notes %}
    <p>
        Date added:    {{ note.date_added }}
        {{ note.note|urlize|url_target_blank|linebreaks }}
    </p>
{% endfor %}

Then on the same page I have a form to add a new note. This note form is an ajax form and returns the newly submitted note back to the page and appends it at the end of the already existent note area.

I don't like this because I have to maintain the same html structure both in the page for the initial load, as well as in the response from the ajax form.

Is there a way to put a call to another template, inside of a template (in this for loop) so I can maintain the note formatting in one location only?

Thanks.


Perhaps you're looking for the "include" tag: http://docs.djangoproject.com/en/dev/ref/templates/builtins/#include

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号