Reputation: 2973
I was working with 2 applications that are within a DJango project: "customer" and "vendors". Each application has a HTML file named "testindex.html".
Whenever I typed:
http://myhost/customer/basic_info
the correct page would show up
If I typed:
http://myhost/vendors/basic_info
the page from http://myhost/customer/basic_info
would show up
I found out that it was due to caching (since both applications use "testindex.html"). So again, "testindex.html" is caching.
How can one get around this problem?
TIA
Details are listed below. I have the following views defined:
urls.py for the project
urlpatterns = [
... snip ...
url(r'^customer/', include('libmstr.customer.urls')),
url(r'^vendors/', include('libmstr.vendors.urls')),
]
views.py for customer
from django.shortcuts import render
def basic_info(request):
return render(request, 'testindex.html', {})
views.py for vendors
from django.shortcuts import render
def basic_info(request):
return render(request, 'testindex.html', {})
urls.py for customers
from django.conf.urls import url
from . import views
# list of templates
app_name = 'customer'
urlpatterns = [
url(r'^basic_info/$', views.basic_info, name='basic_info'),
]
urls.py for vendors
from django.conf.urls import url
from . import views
# list of templates
app_name = 'vendors'
urlpatterns = [
url(r'^basic_info/$', views.basic_info, name='basic_info'),
]
Upvotes: 1
Views: 273
Reputation: 309099
It sounds like you have two templates, customers/templates/testindex.html
and vendors/templates/testindex.html
.
When you call render(request, 'testindex.html', {})
, the app directories template loader searches the templates directory for each app in INSTALLED_APPS
, and stops the first time it finds a match. If customers
is above vendors
in INSTALLED_APPS
, then it will always use the customers template.
For this reason, Django recommends that you name your templates customers/templates/customers/testindex.html
and vendors/templates/vendors/testindex.html
, and change your views to use customers/testindex.html
and vendors/testindex.html
. This way you avoid clashes.
Upvotes: 2