Reputation: 8316
how can i use different template in different application.in a project i have two app 1)Site 2)Ad .I want to use default template in Ad but different in Site..How to ?OR in the template is there is a way to use 'if condition' as i have to change only two lines in the templates.
Upvotes: 0
Views: 418
Reputation: 1609
Pl. check the links to the question I had raised for which the answer is provided by Yuji T
How to use 2 different change_list.html for 2 applications in the same django project
Upvotes: 0
Reputation: 36373
First of all, you are never bound to use same template in different application. Different apps can use different templates, as common practice these days are to place template directories in respective app folder.
Moreover, for change of two lines, you can alwayz use `
{% if condition %}
something
{% else %}
some other thing
{% endif %}
or
{% ifequal var 'var' %}
something
{% else %}
some other thing
{% endifequal %}
All in same template.
Edit
If you say you want to use same templates in diff applications, you can apply path of template considering the facts that, firstly django template loader will look for a template in same app directory, then in projects's root directory, and if not found, it will look for it django's own template source.
So if you want to use template anywhere, you can place them in a folder called templates, placed in the same path where your apps directories are. (i.e. root of the project).
projectroot/app1/templates/app1.html
projectroot/app2/templates/app2.html
projectroot/app3/
projectroot/templates/common.html
likewise common.html can be available to all apps.
Upvotes: 2
Reputation: 10311
Use template inheritance http://www.djangobook.com/en/1.0/chapter04/ Define a base template and change only the desired block.
Upvotes: 0