Solution 1 :

Firstly you shouldn’t access page by .html it should be accessed by url only.

You are already using shop/ here:

path('shop/', include('shop.urls')),

So you should avoid using it in your sub-urls below.

Else you will have to access by shop/shop/cart/ instead of shop/cart/.

Change the urls as below:

urlpatterns = [
    path("", views.index, name="ShopHome"),
    path("cart/", views.cart, name="Cart"),
    path("checkout/", views.checkout, name="Checkout"),
    path("contact/", views.contact, name="ContactUs"),
    path("register/", views.register, name="Register"),
    path("product_details/", views.product_details, name="ProductDetails"),
    path("products/", views.products, name="Products"),
]

This should work fine for you.

Problem :

*I have creted a shop app now in it *

shop/urls.py

from django.urls import path
from . import views

urlpatterns = [
    path("", views.index, name="ShopHome"),
    path("shop/cart/", views.cart, name="Cart"),
    path("shop/checkout/", views.checkout, name="Checkout"),
    path("shop/contact/", views.contact, name="ContactUs"),
    path("shop/register/", views.register, name="Register"),
    path("shop/product_details/", views.product_details, name="ProductDetails"),
    path("shop/products/", views.products, name="Products"),
]

the main project urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
    path('admin/', admin.site.urls),
    path('shop/', include('shop.urls')),

]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


views.py

from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse


def index(request):
    return render(request, 'shop/index.html')


def register(request):
    return render(request, 'shop/register.html')


def contact(request):
    return render(request, 'shop/contact.html')


def products(request):
    return render(request, 'shop/products.html')


def product_details(request):
    return render(request, 'shop/product_details.html')


def cart(request):
    return render(request, 'shop/cart.html')


def checkout(request):
    return render(request, 'shop/checkout.html')

models.py

from django.db import models

# Create your models here.


class Product(models.Model):
    name = models.CharField(max_length=300)
    slug = models.SlugField(max_length=150)
    description = models.TextField()
    image = models.ImageField(upload_to='shop/images', default='')
    manufacturer = models.CharField(max_length=300, blank=True)
    price_in_dollars = models.DecimalField(max_digits=6, decimal_places=2)

    def __str__(self):
        return self.name

setting.py the installed apps part



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


]

apps.py

from django.apps import AppConfig


class ShopConfig(AppConfig):
    name = 'shop'

admin.py

from django.contrib import admin

# Register your models here.

from . models import Product

admin.site.register(Product)

*the html is not loading in the browser its showing *


Page not found (404)
Request Method:     GET
Request URL:    http://127.0.0.1:8000/shop/products.html

Using the URLconf defined in mac.urls, Django tried these URL patterns, in this order:

    admin/
    shop/ [name='ShopHome']
    shop/ cart/ [name='Cart']
    shop/ checkout/ [name='Checkout']
    shop/ contact/ [name='ContactUs']
    shop/ register/ [name='Register']
    shop/ product_details/ [name='ProductDetails']
    shop/ products/ [name='Products']

The current path, shop/products.html, 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.

i ahve tried many other htmls but only the main /shop page is appearing no other url is working like /shop/product or /shop/cart non of them are working ive been trying to fic it for a long time now

Comments

Comment posted by Astik Anand

@AntonyKJohn, do let me know if this works for you.

Comment posted by 127.0.0.1:8000/shop/products

it did not work bro it shows the same error even after trying the method you suggested by

Comment posted by Astik Anand

@AntonyKJohn, I missed the question info, can you check the updated answer and let me know if this works for you.

Comment posted by Astik Anand

@AntonyKJohn, glad it helped.

By