Customise templates not taking any effect

158 views
Skip to first unread message

Steffen Mogensen

unread,
Apr 4, 2020, 4:00:29 PM4/4/20
to django-oscar
I've just started out with Django-oscar, and I do think it will be an amazing framework to work with, as soon as I figure out why it is not behaving as expected 😛

So fare, I have followed the tutorial to get started. But, I can't seem to get the part right, where I can customize the layout.

As written in the tutorial, I have setup the locations for my templates.

location = lambda x: os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', x)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
location('templates'),
],
'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.checkout.context_processors.checkout',
'oscar.apps.customer.notifications.context_processors.notifications',
'oscar.core.context_processors.metadata',
],
},
},
]

and made a folder inside the application (simular to other Django projects), where I have put in the base.html file. But, no mather what I change inside the .html file, it has no effect on the project. So, I guess it is not detecting the Base.html file (or any other file in the template folder).
I might be missing something (even though I have followed the tutorial very carefully). But, I can't seem to figure out what I am doing wrong. Anyone who has some good knowledge on setting it up, so that I would be able to start making changes to the layout?

Samir Shah

unread,
Apr 5, 2020, 2:10:53 AM4/5/20
to django-oscar
Hi Steffen,

Oscar's base template is "oscar/base.html", not just "base.html". It looks to me like that is most likely your problem. To override you need to put your template in "templates/oscar/base.html" rather than "templates/base.html".

Same applies for all other Oscar templates - they are prefixed with the "oscar/" namespace.

Hope this helps,

Samir

Steffen Mogensen

unread,
Apr 5, 2020, 3:13:36 AM4/5/20
to django-oscar
Hi Samir,

Amazing! That was apparently what I was missing. After moving the html files into "templates/oscar/" it just worked like a charm.
Thanks a bunch!

Tunde Ojo

unread,
Jun 10, 2021, 12:53:09 PM6/10/21
to django-oscar
HI Steffen,

can you kindly guide me through the template customization process. 


base_dir - C:\django_oscar\bakeryshop
static root - "C:\django_oscar\bakeryshop\static"
staticfiles dir - "C:\django_oscar\bakeryshop\staticfiles"
static url - "/static/"

my settings file location. C:\django_oscar\bakeryshop\bakeryshop\settings.py

a snippet of my settings.py

ROOT_URLCONF = 'bakeryshop.urls'

# Path helper
location = lambda x: os.path.join(
    os.path.dirname(os.path.realpath(__file__)), x)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
]

To override the original oscar\base.html and display myicon.ico as my favicon I have the following
C:\django_oscar\bakeryshop\templates\oscar\base.html 

and 

C:\django_oscar\bakeryshop\static\oscar\my_icon.ico

however, my favicon (i.e my_icon.ico) does not show in my browser when i include the following in  C:\django_oscar\bakeryshop\templates\oscar\base.html 

{% block favicon %}
        <link rel="shortcut icon" href="{% static './oscar/myicon.ico' %}" />
{% endblock %}

I will appreciate any and all the help i can get on this issue as I am at my wits end.


Reply all
Reply to author
Forward
0 new messages