I'm trying to create one template for all apps, but with different base (related to app).
i'm using django_hosts:
hosts.py:
from django_hosts import patterns, host
host_patterns = patterns('',
host(r'app1', 'app1.urls', name = 'app1'),
host(r'(app2|application2)','app2.urls', name = 'app2'),
)
tree:
templates/document.html
app1/templates/app1/base.html
app2/templates/app2/base.html
templates/document.html:
{% extends base %}
And the idea is:
when I go to http://app1.example.com/document/
i will see templates/document.html
extended with app1/templates/app1/base.html
, and if I go to http://app2.example.com/document/
or http://application2.example.com/document/
extended with app2/templates/app2/base.html
generally it works if I use in
app1/views.py:
(...)
context={ 'base' : 'app1/base.html' }
return render(request,'document.html', context)
app2/views.py:
(...)
context={ 'base' : 'app2/base.html' }
return render(request,'document.html', context)
But I want to remove context 'base' from every views' def .
I can't use app1/context_processors.py
and app2/context_processors.py
, because it would override themselves, because context_processors are global not app local.
There's an idea:
#main/contexts.py
from django.core.urlresolvers import resolve
def appname(request):
return {'appname': resolve(request.path).app_name}
but i don't have urls.py with includes, because i have hosts definition....
It was easier, than I supposed...
context_processors.py:
But 5 hours of searching are lost...