Nothing appears in the URL "http: // localhost: 8000 / buy /"

I wanted to include an e-commerce portal on my site, and I did everything that is listed on the "Create your own store" page, as indicated in the Django-Oscar documentation, only in urls.py instead

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

I added

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

but the problem is that when I click on the url it shows nothing and gives no error.

Any idea what could be the problem?

Maybe some URLs collide or something else is trivial, but I can't figure out where to start debugging.

Urls.py file

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

Settings.py file

 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

+6
source share
5 answers

I see that in the second screenshot of localhost:8000/buy/catalogue/ you really get the result. It would seem that you did not define your own templates or somehow you need to fix your TEMPLATE_DIRS or TEMPLATE_CONTEXT_PROCESSORS settings.

I did not use oscar, but the fact that you get something on the screen seems to me a problem loading the template.

See their docs on setting template_context_processors

Can you post your settings please?

Update:

After viewing your settings, template_context_processors look right. Then I looked at the oscar templates and they seem to expand without qualifying the oscar catalog. For example, layout.html (/oscar/templates/oscar/layout.html) does the following:

 {% 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 will probably use this instead. Can you try to temporarily rename this file (if it exists) and see what happens?

+5
source

urls.py

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

Then in your application directory create a file called urls.py

app/urls.py

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

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 this:

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

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

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

Hope this helps.

0
source

You may have encountered name conflicts with patterns. The default Django template loader, which I assume you are using, may be a little unintuitive. When you request a template with the given name, it passes through your INSTALLED_APPS tuple in the settings in order, checking each of them in the templates folder. If in two different applications there are two templates with the same path, it will always be the first one that it finds.

That's why the recommendation in django docs is to β€œuse the namespace” for your templates, saving them all in a different folder with the name of your application, in the templates folder. Oscar does this, so their templates are in oscar/templates/oscar , so they should not collide with any other applications, but I’m wondering if you put the oscar folder in the templates of one of your applications, maybe when faced with base.html

0
source

The problem is that django-oscar should not be included under a subpath, for example /buy/ . In their documentation, their example shows the installation:

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

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

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

0
source

Source: https://habr.com/ru/post/986422/


All Articles