I am trying to add a django-oscar shop to an existing django website.
My problem is that the templates of the two are somehow clashing, such that I can either see the existing website, or the shop, but not both.
Here is the overarching urls.py:
from django.conf.urls import include, url
from django.contrib import admin
from oscar.app import application
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('main.urls')),
# oscar
url(r'^shop/', include(application.urls)),
]
And in the settings:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# os.path.join(BASE_DIR, 'templates'),
OSCAR_MAIN_TEMPLATE_DIR
],
# 'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'oscar.apps.search.context_processors.search_form',
'oscar.apps.promotions.context_processors.promotions',
'oscar.apps.checkout.context_processors.checkout',
'oscar.apps.customer.notifications.context_processors.notifications',
'oscar.core.context_processors.metadata',
'main.context_processors.google_analytics'
],
'loaders': [
'django.template.loaders.app_directories.Loader',
'django.template.loaders.filesystem.Loader',
],
},
},
]
If I switch the order of the loaders, either the original website (in app 'main'), or the Oscar shop, can no longer be accessed/viewed. So I'm not sure what esoteric detail I'm overlooking, and the docs don't cover this. Cheers.
The issue you're having is that your template names conflict with Oscar's. Oscar has it's own base.html
, which is what the template loader will find if you list that loader first, instead of your own base.html
. Django will use the first one it finds.
This is a known issue with Oscar - unfortunately there is no backwards compatible way to fix it, and so it hasn't been addressed for some time.
Changing Oscar's behaviour is quite difficult so I'd suggest you try and change your template structure instead. Specifically, you should namespace all your app templates. So if your app is called myapp
, then put the base template in myapp/templates/myapp/base.html
. You would then refer to this in other templates as {% extends 'myapp/base.html' %}
. Similarly put all other templates in templates/myapp/
.
This will ensure that your templates do not clash with Oscar's, and the problem should go away.