Customising Django-oscar templates

2,607 views
Skip to first unread message

MONICA PHALSWAL

unread,
Sep 17, 2013, 12:38:49 AM9/17/13
to django...@googlegroups.com
Hi, I tried following the recipe given in the official docs but, it didn't work. So could somebody just explain it step-by-step. Also I'm building my shop in a virtualenv, I tried finding the oscar template folder but couldn't find it. Please help!

Michael Lind Hjulskov

unread,
Sep 17, 2013, 4:04:38 AM9/17/13
to django...@googlegroups.com
Hi

I'll give it a try
Im still newbie so hope its correct

The template files are located in the oscar/templates/oscar/
Leave them there and copy those files You want to make changes to, to Your own templates dir
example myapp/templates/partials/footer.html

2 possibilities inside the html file
Using "extends oscar/partials/footer.html" You can change only a block in the original
or just replacing all the content with your own content

Hope this helps

Michael

David Winterbottom

unread,
Sep 18, 2013, 5:01:13 PM9/18/13
to django-oscar
Monika - ensure you have OSCAR_MAIN_TEMPLATE_DIR (imported from oscar) in your TEMPLATE_DIRS setting.  Then you can override individual blocks within templates to customise.  It's normal to have your own templates directory too that you can use to override entire template files.

See the sandbox site for a working example:




--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-oscar/0500fc5d-72d6-4220-a903-ee386a2dfb34%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
David Winterbottom
Head of Programming

Tangent Labs
84-86 Great Portland Street
London W1W 7NR
England, UK

edith salento

unread,
Sep 25, 2013, 3:15:02 PM9/25/13
to django...@googlegroups.com, david.win...@tangentlabs.co.uk
Hi David!
I have the same problem: I follow the method2's instructions to customise templates and it doesn't work. I want to customize the navbar so I did a copy of the partials/nav_primary.html in my templates dir : myapp/templates/partials/nav_primary.html. Then I added the {% extends oscar/partials/nav_primary.html %} to this file. And I add some buttons, but they don't appear... It seems that the loader doesn't load my file...

Thanks for your help!

Edith

David Winterbottom

unread,
Sep 25, 2013, 5:36:00 PM9/25/13
to django-oscar
Edith,

Do you have your own templates directory in your TEMPLATE_DIRS setting (as mentioned below)?  This is the key change for the customisation technique to work.  I suggest using the debug toolbar to debug these template issues - it has a templates panel which shows every template loaded.

Have a look at Oscar's sandbox site for an example of this:

Hope that helps, 
David


For more options, visit https://groups.google.com/groups/opt_out.

edith salento

unread,
Sep 26, 2013, 10:23:37 AM9/26/13
to django...@googlegroups.com, david.win...@tangentlabs.co.uk
Hi David,

Yes I have my templates directory in my TEMPLATE_DIRS, like this:

location = lambda x: os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', x)
from oscar import OSCAR_MAIN_TEMPLATE_DIR

TEMPLATE_DIRS = (
    location('templates'),
    OSCAR_MAIN_TEMPLATE_DIR,
)

I tried to modify the location variable, removing the '..' argument like in your exemple, but it didn't work.
I will try with the debug toolbar, to find out what's wrong.

Thanks for your answer!

Edith

edith salento

unread,
Sep 26, 2013, 11:30:49 AM9/26/13
to django...@googlegroups.com
OK

Problem resolved:

location('myapp/templates')

Thanks a lot

Edith

HARSHIT singhal

unread,
Dec 31, 2014, 1:34:27 AM12/31/14
to django...@googlegroups.com
hello,


can you help me how to customize my front end.. i want to change my full front end of my shop.......

as i read how to make our own shop according to this i had completed.... but my requirement to change a view of my shop means how to change a frontend

David Winterbottom

unread,
Jan 4, 2015, 5:54:57 PM1/4/15
to django-oscar

--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.

YusufSalahAdDin

unread,
Aug 11, 2016, 10:00:00 PM8/11/16
to django-oscar

vaibhav jain

unread,
Jan 28, 2017, 7:09:51 AM1/28/17
to django-oscar, david.win...@tangentlabs.co.uk

Hi David,

I am trying to override the base.html but couldn't. Copied the template under local DIR (templates/oscar/base.html) But Django-Debug-Toolbar shows 

base.html
/home/prime/.virtualenvs/myshop/local/lib/python2.7/site-packages/oscar/templates/oscar/base.html

Is loading not mine. What could be the issue ??

#settings.py

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR('templates'),
OSCAR_MAIN_TEMPLATE_DIR,
ACCOUNTS_TEMPLATE_DIR,
],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'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',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
],
},
},
]

Alex House

unread,
Jan 30, 2017, 6:15:14 AM1/30/17
to django-oscar, david.win...@tangentlabs.co.uk
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)

суббота, 28 января 2017 г., 22:09:51 UTC+10 пользователь vaibhav jain написал:

vaibhav jain

unread,
Jan 30, 2017, 7:16:40 AM1/30/17
to django-oscar, david.win...@tangentlabs.co.uk
Hi Alex,

Its already there. Somehow my custom template aren't picked up by django.

Pradnya Bamane

unread,
Aug 4, 2020, 11:44:52 PM8/4/20
to django-oscar
Follow this tutorial https://youtu.be/-Mf02TvI7Jw, everything for customization and extend Oscar template is explained step by step with code demo here.
Reply all
Reply to author
Forward
0 new messages