Local templates not loading in django-oscar

1k Views Asked by At

I want to customize the layout of my Django-Oscar site according to my requirements(changing header etc)

I tried method 1 as described in Django Oscar documentation How to customise templates

But it is not loading the templates from my local directory(templates/oscar)even though I have copied them instead it is loading templates from the main installation directory.

I think their could be some problem in my settings.py file but I am not able to find it.

Settings.py

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

import os
import sys
from oscar import get_core_apps
from oscar import OSCAR_MAIN_TEMPLATE_DIR
from oscar.defaults import *
from django.core.urlresolvers import reverse_lazy

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

# sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))  # to store apps in apps/ directory


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''

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

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)

TEMPLATE_DIRS = (
    location('templates'),
    os.path.join(BASE_DIR, 'templates').replace('\\', '/'),
    OSCAR_MAIN_TEMPLATE_DIR,
)

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
    'apps.users',
    'apps.doorstep',
    'apps.cars',
    'django_markdown',
    'social.apps.django_app.default',
    # 'crispy_forms',
    'django.contrib.sites',
    # 'zinnia_threaded_comments',   # app for zinnia threaded comments
    'django_comments',  # zinnia-blogging prerequisite
    'mptt',             # zinnia-blogging prerequisite
    'tagging',          # zinnia-blogging prerequisite
    'zinnia',           # zinnia itself
    'compressor',
    ] + get_core_apps()
# specifying the comments app
# COMMENTS_APP = 'zinnia_threaded_comments'

MIDDLEWARE_CLASSES = (
    '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 backend used by python-social-auth
AUTHENTICATION_BACKENDS = (
    'social.backends.facebook.FacebookOAuth2',
    'social.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
    'oscar.apps.customer.auth_backends.EmailBackend',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    "social.apps.django_app.context_processors.backends",
    "social.apps.django_app.context_processors.login_redirect",
    "django.contrib.auth.context_processors.auth",
    "django.contrib.messages.context_processors.messages",
    "django.core.context_processors.i18n",
    "django.core.context_processors.request",
    "zinnia.context_processors.version",
    "django.core.context_processors.debug",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    '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'
)



ROOT_URLCONF = '{project_name}.urls'

WSGI_APPLICATION = '{project_name}.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "",
        'USER': '',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3306'
    }
}

# Internationalization

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOGIN_URL = '/users/login/'

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

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



STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'staticfiles'),


)
REGISTRATION_INVALID = 50
MESSAGE_TAGS = {
    REGISTRATION_INVALID: 'InvalidDetails',
}
# temporary , should not be in settings file
SOCIAL_AUTH_FACEBOOK_KEY = ""
SOCIAL_AUTH_FACEBOOK_SECRET = ""
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = ""
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = ""

LOGIN_REDIRECT_URL = '/blog/'

# ------------------------------------ #
# Settings for sending email #

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# ------------------------------------ #


# site id for django sites framework
SITE_ID = 1

# configuration settings for  django-zinnia
ZINNIA_PING_EXTERNAL_URLS = False
ZINNIA_SAVE_PING_DIRECTORIES = False
ZINNIA_MARKUP_LANGUAGE = 'markdown'
ZINNIA_UPLOAD_TO = 'uploads/zinnia/'
# TimeZone Settings
USE_TZ = True

# ------------------------ #
# django oscar search settings
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    },
}
# django oscar settings
OSCAR_SHOP_NAME = ''
OSCAR_DEFAULT_CURRENCY = 'INR'

Any idea what could be the issue here?

1

There are 1 best solutions below

0
On

Try to change

location('templates'),
os.path.join(BASE_DIR, 'templates').replace('\\', '/'),

to

os.path.join(BASE_DIR, 'templates')

with

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

it helped me.