0

Django is awesome, was designed with folder of templates to find all templates was include in your app. If you work with multiple app in your project, you just create a folder templates in your project or app. Django will find at all, even though with different app.

This tutorial was asked on stackoverflow, and was answer with Carles Barrobés. This answer of it:

As long as the apps are in INSTALLED_APPS and the template loader for apps dirs is enabled, you can include any template from another app, i.e.:

{% include "header.html" %}

… since your templates are located directly in the templates dir of your app. Generally, in order to avoid name clashes it is better to use:

app1/
    templates/
        app1/
            page1.html
            page2.html
app2/
    templates/
        app2/
            page1.html
            page2.html

And {% include "app1/page1.html" %} or {% include "app2/page1.html" %}

But: for keeping a consistent look and feel, it is so much better to use template inheritance rather than inclusion. Template inheritance is one of the really good things of the Django template system, choose inheritance over inclusion whenever it makes sense (most of the time).

My recommendations:

  • Have a base template for your project (“base.html” is the default convention) with header and footer and a {%block content%} for your main content.
  • Have your other templates inherit form base.html {% extends "base.html" %} and override the content section

See another response to this question for links to the doc.

Refference: http://stackoverflow.com/questions/4571686/django-include-template-from-another-app

python django templates

Your Answer

blog comments powered by Disqus