Create Virtual Environment

➜ ~ virtualenv ~/Environments/env_oscar

Activate Virtual Environment

➜ ~ source ~/Environments/env_oscar/bin/activate

Install Following
pip install django-oscar==1.2.2
pip install pycountry==1.20
pip install django-compressor==2.0
pip install ipython
Create Project
(env_oscar) ➜  ~ django-admin.py startproject frobshop
(env_oscar) ➜  ~ cd Projects

Settings.py

from oscar.defaults import *
from oscar import OSCAR_MAIN_TEMPLATE_DIR

remove 'APP_DIRS': True, from TEMPLATES = []

add DIRS to from TEMPLATES = []

location('templates'),
OSCAR_MAIN_TEMPLATE_DIR,

add this in context_processors in TEMPLATES = []

'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',

'create new dict in OPTIONS > loaders' in TEMPLATES = []

'loaders': [
    'django.template.loaders.filesystem.Loader', 
    'django.template.loaders.app_directories.Loader', 
    'django.template.loaders.eggs.Loader', 
],

final TEMPLATES will look like this

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

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            location('templates'), 
            OSCAR_MAIN_TEMPLATE_DIR,
        ],        
        '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',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader', 
                'django.template.loaders.app_directories.Loader', 
                'django.template.loaders.eggs.Loader', 
            ],
        },
    },
]

modify INSTALLED_APPS to be a list, add django.contrib.sites, django.contrib.flatpages, compressor and widget_tweaks and append Oscar’s core apps. Also set SITE_ID:

from oscar import get_core_apps

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'django.contrib.sites',
    'django.contrib.flatpages',

    'compressor',
    'widget_tweaks',
]+ get_core_apps()

SITE_ID = 1

Next, add oscar.apps.basket.middleware.BasketMiddleware and django.contrib.flatpages.middleware.FlatpageFallbackMiddleware to your MIDDLEWARE_CLASSES setting.

MIDDLEWARE_CLASSES = (
    ...
    'oscar.apps.basket.middleware.BasketMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

Set your auth backends to:

AUTHENTICATION_BACKENDS = (
    'oscar.apps.customer.auth_backends.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)

Set your haystack connections to:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    },
}

Set databases to:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.sqlite3',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
        'ATOMIC_REQUESTS': True,
    }
}

add static root

STATIC_ROOT = os.path.join(BASE_DIR, "static")
Change Currency
OSCAR_DEFAULT_CURRENCY = "INR"
Change Timezone
TIME_ZONE = 'Asia/Kolkata'

Ref settings.py

"""
Django settings for frobshop project.

Generated by 'django-admin startproject' using Django 1.9.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os
from oscar.defaults import *
from oscar import OSCAR_MAIN_TEMPLATE_DIR
from oscar import get_core_apps

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%jab=7$zdwrzzi_p$b+7_$8n*96+v&=ys#(n@(bycb(3!=j5kx'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'django.contrib.sites',
    'django.contrib.flatpages',

    'compressor',
    'widget_tweaks',
    'debug_toolbar',
]+ get_core_apps()

SITE_ID = 1

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

    'oscar.apps.basket.middleware.BasketMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
]


AUTHENTICATION_BACKENDS = (
    'oscar.apps.customer.auth_backends.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)


HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    },
}

ROOT_URLCONF = 'frobshop.urls'

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

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            location('templates'), 
            OSCAR_MAIN_TEMPLATE_DIR,
        ],        
        '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',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader', 
                'django.template.loaders.app_directories.Loader', 
                'django.template.loaders.eggs.Loader', 
            ],
        },
    },
]

WSGI_APPLICATION = 'frobshop.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.sqlite3',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
        'ATOMIC_REQUESTS': True,
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Kolkata'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

urls.py

from django.conf.urls import include, url
from django.contrib import admin
from oscar.app import application
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include(application.urls)),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Migrate project
(env_oscar) ➜  frobshop python manage.py migrate
Populate countries
(env_oscar) ➜  frobshop python manage.py oscar_populate_countries
Successfully added 249 countries.
Create Superuser
(env_oscar) ➜  frobshop python manage.py createsuperuser
Runserver
(env_oscar) ➜  frobshop python manage.py runserver 0.0.0.0:8000

Template Editing

install following
(env_oscar) ➜  frobshop pip install django-debug-toolbar
add debug_toolbar to installed apps
INSTALLED_APPS = [
    ...
    'debug_toolbar',
]+ get_core_apps()
Steps to override home templatep

Click on debug toolbar button and Select Templates Home Page

Notice the url of home page ie. promotions/home.html

Template paths

Now we know which file to extend lets override promotions/home.html

first create home.html in templates/promotions/ directory

(env_oscar) ➜  frobshop mkdir templates
(env_oscar) ➜  frobshop cd templates 
(env_oscar) ➜  templates mkdir promotions
(env_oscar) ➜  templates cd promotions  
(env_oscar) ➜  promotions touch home.html

home.html

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

{% block content %} 
    <h1>Hello</h1> 
{% endblock content %}

my home page

results matching ""

    No results matching ""