I am trying to make an e-commerce website in django. I want to lay the rough pipeline using this code but when i search, for example- http://127.0.0.1:8000/shop/about - This 404 Error come on my screen. Please tell me what to do.
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/shop/about
Using the URLconf defined in ekona.urls, Django tried these URL patterns, in this order:
admin/
shop [name='ShopHome']
shop about [name='about']
shop contact/ [name='ContactUs']
shop tracker/ [name='Tracker']
shop search/ [name='Search']
shop prodview/ [name='ProdView']
shop checkout/ [name='Checkout']
blog
The current path, shop/about, didn’t match any of these.
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that
to False, and Django will display a standard 404 page.
My settings.py is -
"""
Django settings for ekona project.
Generated by 'django-admin startproject' using Django 4.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-o5!u%!k$n7a)q_wqj$av#t7%xplhhtt1mkefs)(q$*79$b6guq'
# 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',
'blog',
'shop',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'ekona.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'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',
],
},
},
]
WSGI_APPLICATION = 'ekona.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.0/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',
},
]
My urls.py for this 'shop' page is-
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name='ShopHome'),
path('about', views.about, name='AboutUs'),
path('contact/', views.contact, name='ContactUs'),
path('tracker/', views.tracker, name='Tracker'),
path('search/', views.search, name='Search'),
path('prodview/', views.productView, name='ProdView'),
path('checkout/', views.checkout, name='Checkout'),
]
My views.py for this 'shop' page is-
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return render(request,'shop/index.html')
def about(request):
return HttpResponse("We are at about")
def contact(request):
return HttpResponse("We are at contact")
def tracker(request):
return HttpResponse("We are at tracker")
def search(request):
return HttpResponse("We are at search")
def productView(request):
return HttpResponse("We are at product view")
def checkout(request):
return HttpResponse("We are at checkout")
Please tell me why's the error coming
CodePudding user response:
http://127.0.0.1:8000/shop/about
You don't have this url in your urls.py try:
http://127.0.0.1:8000/about
without /shop/
edit: probably you have 2 urls.py files. One in project folder, and one in app folder. In your project urls.py you should add line:
path('shop/', include("shop.urls")),
and in yout app urls.py add line:
app_name = "shop"
CodePudding user response:
In ekona.urls add the following:
path('shop/', include("shop.urls")),
Also, make sure to import include like so:
from django.urls import path, include