Sebastian Auberger
Sebastian Auberger

Reputation: 480

Django: Include template from another app

I have a project app and a files app. In the project.html file I want to include the file_list.html file. Such that all the files corresponding to a project are shown on the project page.

project.html (Project app)

{% extends "site_base.html" %}
...
{% block body %}
...
<div id="files">
    <p>More here soon but in the meantime, here's a link to the
        <a href="{% groupurl file_list project %}">file list</a>
    </p>
</div>
...
{% endblock body %}

Instead of the link here to the file list I would like to directly insert the file list.

file_list.html (Files app)

{% extends "site_base.html" %}
{% block body %}

{% for file in files %}
<tr>
    <td>{{ file.filename }}</td>
</tr>
{% endfor %}

{% endblock body %}

I came up with the following possibilities, but I'm not sure what's actually working and best practice

What would be the best solution in this case. Are there any other possibilities?

Upvotes: 2

Views: 1356

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599956

An inclusion tag is the only possible answer here, as none of the others will include the actual list of files in the template context. This is exactly what inclusion tags are for.

Upvotes: 3

Related Questions