Innovate anywhere, anytime withruncode.io Your cloud-based dev studio.
Django

How to Create your Own E-Commerce Shop Using Django-Oscar

2022-07-19

Oscar is an open-source ecommerce framework for Django. Django Oscar provides a base platform to build an online shop.

Oscar is built as a highly customisable and extendable framework. It supports Pluggable tax calculations, Per-customer pricing, Multi-currency etc.

1. Install Oscar

$ pip install django-oscar

2. Then, create a Django project

$ django-admin.py startproject <project-name>

After creating the project, add all the settings(INSTALLED_APPS, MIDDLEWARE_CLASSES, DATABASES) in your settings file

And you can find the reference on how to customize the Django Oscar app, urls, models and views here.

Customising/Overridding templates:

To override Oscar templates, first you need to update the template configuration settings as below in your setting file.

import os

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

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',

)

from oscar import OSCAR_MAIN_TEMPLATE_DIR

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

Note: In the 'TEMPLATE_DIRS' setting, you have to include your project template directory path first and then comes the Oscar's template folder which you can import from oscar.

By customising templates, you can just replacing all the content with your own content or you can only change blocks using "extends"

Ex: Overriding Home page

{% extends 'oscar/promotions/home.html' %}

{% block content %}
    Content goes here
    ...
    ...
{% endblock content %}