views:

149

answers:

2

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.

+2  A: 

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.

simplyharsh
i want to use different template in different app.Using If in template is not a good solution as in my project i have about 10 app.I have 2 template ready.I just want to use them using template loader but it is not loading
ha22109
A: 

Use template inheritance http://www.djangobook.com/en/1.0/chapter04/ Define a base template and change only the desired block.

zalew