ofnowhere
ofnowhere

Reputation: 1135

Django Oscar: Nothing showing up at URL "http://localhost:8000/buy/"

I wanted to include an ecommerce portal on my website and I have done everything as given on the "Create your Shop page" as given in Django-Oscar documentation, just that in urls.py instead of

url(r'', include(application.urls)),

I have added

url(r'^buy/', include(application.urls)),

but the problem is that when I hit the url it is neither showing anything nor giving an error.

Any idea what could be the problem?

It could be some urls are clashing or something else trivial but I am not able to understand from where to start debugging.

File urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
from view import AboutusView, TwentySevenView
import apps.users.views
from django.conf import settings

    #oscar urls
    from oscar.app import application

    admin.site.site_header = ''
    urlpatterns = patterns('',
                           # Examples:
                           # url(r'^$', 'torquehp.views.home', name='home'),
                           # url(r'^users/', include('users.urls')),
                           url(r'^i18n/', include('django.conf.urls.i18n')),
                           url(r'^admin/', include(admin.site.urls)),
                           url(r'^about-us/$', AboutusView.as_view(), name="about-us"),
                           url(r'^24x7/$', TwentySevenView.as_view(), name="24x7"),
                           url(r'^$', apps.users.views.user_home, name="home"),
                           url(r'^markdown/', include('django_markdown.urls')),
                           url(r'^users/', include('apps.users.urls')),
                           url(r'^doorstep/', include('apps.doorstep.urls')),
                           url(r'^cars/', include('apps.cars.urls')),
                           url('', include('social.apps.django_app.urls', namespace='social')),
                           # urls for zinnia
                           url(r'^blog/', include('zinnia.urls', namespace='zinnia')),
                           url(r'^comments/', include('django_comments.urls')),
                           url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
                               {'document_root': settings.MEDIA_ROOT, }),
                           # oscar URLs
                           url(r'^buy/', include(application.urls)),
    )

File settings.py

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

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

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',
    'django.contrib.sites',
    'django_comments', 
    'mptt',             
    'tagging',          
    'zinnia',           
    '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'
)

# TEMPLATE_LOADERS = (
#     'app_namespace.Loader',
# )

ROOT_URLCONF = 'torquehp.urls'

WSGI_APPLICATION = 'torquehp.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/"
TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates').replace('\\', '/'),
    location('templates'),
    OSCAR_MAIN_TEMPLATE_DIR,
)

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 s=oscar search settings
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    },
}

Screenshots:

http://localhost:8000/buy/ enter image description here

http://localhost:8000/buy/catalogue/

enter image description here

Upvotes: 6

Views: 2693

Answers (5)

Esteban
Esteban

Reputation: 2513

I see that in your second screenshot localhost:8000/buy/catalogue/ you actually get a result. It would seem as if you haven't defined your own templates or somehow need to fix your TEMPLATE_DIRS or TEMPLATE_CONTEXT_PROCESSORS settings.

I haven't used oscar, but that fact that you get something on screen seems like a template loading issue to me.

See their docs about setting the template_context_processors

Can you post your settings please?

Update:

After seeing your settings, the template_context_processors look correct. I next looked at oscar's templates and they seem to extend without qualifying the oscar directory. For example, layout.html (/oscar/templates/oscar/layout.html) does this:

{% extends 'base.html' %}

Now, if you also have a 'base.html' file in your own project directory, say project_dir/templates/base.html, then it'll probably use that instead. Can you try to temporarily rename that file (if it exists) and see what happens?

Upvotes: 5

Joey Wilhelm
Joey Wilhelm

Reputation: 5819

The problem is that django-oscar is not meant to be included under a sub-path, such as /buy/. In their documentation, their example shows installing it as:

url(r'', include(application.urls)),

If you look at the source of get_urls(), which provides the return value for application.urls, you can see that it does not provide a urlpattern to match r'^$', which is what you would need to match at the URL you are trying to view.

In short, you should follow exactly what the documentation recommends, or you will get unexpected results.

Upvotes: 0

skolsuper
skolsuper

Reputation: 639

Maybe you have a naming collision with templates. Django's default template loader, which I assume you're using, can be a bit unintuitive. When you ask it for a template with a given name, it goes through your INSTALLED_APPS tuple in settings in order, checking in each one for a templates folder. If there are two templates with the same path in two different apps, it will always take the first one it finds.

That's why the recommendation in django docs is to 'namespace' your templates by keeping them all in another folder with the name of your app, within the templates folder. Oscar does this, so their templates are in oscar/templates/oscar, so they shouldn't be colliding with any other apps, but I'm wondering if maybe you put an 'oscar' folder within the templates of one of your apps, possibly clashing with base.html.

Upvotes: 0

Akash Srivastava
Akash Srivastava

Reputation: 292

In app/urls.py add the following line:

url(r'^$',views.index,name='index'),

This will redirect you to the index function in app/views.py In app/views.py do something like that:

def index(request):
  #Your logic here
  return render(request,'urpoll/index.html'{'category':categorys,'ques':ques,'url':url})

This will render index.html with categories,ques,url. In index.HTML so something like that:

{{ if category }}
{{ category }}
{{ endif }}

I hope this will help.

Upvotes: 0

Othman
Othman

Reputation: 3018

urls.py

url(r'^buy/', include("app.urls")),

Then under your app directory create a file called urls.py

app/urls.py

# this is your “http://localhost:8000/buy/”
url(r'^$', ViewName.as_view(), name="thename"),

Upvotes: 1

Related Questions