1

When the default url http://127.0.0.1:8000/ is given then the app is able to get the default page but when I tried to connect with the pages using http://127.0.0.1:8000/customer/ I'm getting this error as a traceback

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/customer/
Using the URLconf defined in crm.urls, Django tried these URL patterns, in this order:

admin/
The current path, customer/, 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.

Here is my code crm/urls.py--->

from django.contrib import admin
from django.urls import path,include


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

]

now accounts/urls.py--->

from django.urls import path
from . import views


urlpatterns = [
    path('', views.home,name="ShopHome"),
    path('products/', views.products,name="ProductsHome"),
    path('customer/', views.customer,name="customerHome"),
]

Now accounts/view.py--->

from django.shortcuts import render
from django.http import HttpResponse



def home(request):
    return HttpResponse('home')

def products(request):
    return HttpResponse('products')

def customer(request):
    return HttpResponse('customer')

and this is myinstalled apps in setting-->

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
]

Please help me out guys I'm struck here for 2 days

Selva
  • 23
  • 5

1 Answers1

0

You need to point to the urls of the accounts app without a leading accounts/:

urlpatterns = [
    path('admin/', admin.site.urls),
    #    ↓↓ empty string
    path('', include('accounts.urls')),
]

otherwise you can access the customer view with:

http://127.0.0.1:8000/accounts/customer/

but that is likely not what you want.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • Sorry I tried in both ways still getting the same error – Selva May 23 '21 at 08:38
  • @Selva: you can not combine both, you should pick *one* of the two. – Willem Van Onsem May 23 '21 at 08:40
  • Yeah That's what I did. I meant I tried each one of them seperatly – Selva May 23 '21 at 08:41
  • @Selva: can you please post the *full* traceback? Please *edit* your question. – Willem Van Onsem May 23 '21 at 08:41
  • You mean the entire code? or some other thing. Sorry not able to get you – Selva May 23 '21 at 08:48
  • @Selva: what exactly does it show when you accessing the URL? When you work with `DEBUG = True`, it should print data to diagnoze the problem. – Willem Van Onsem May 23 '21 at 08:49
  • Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/customer Using the URLconf defined in crm.urls, Django tried these URL patterns, in this order: admin/ The current path, customer, 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.@Willem Van Onsem – Selva May 23 '21 at 08:51
  • 1
    @Selva: what if you use a *trailing* slash: `http://127.0.0.1:8000/customer/` – Willem Van Onsem May 23 '21 at 08:52
  • Already did still the same error? Would you like to connect with me if possible? – Selva May 23 '21 at 08:55
  • @Selva: can you [edit](https://stackoverflow.com/posts/67657695/edit) the question and include the traceback (in a code environment), suc that no post-processing is done on the data through HTML rendering. – Willem Van Onsem May 23 '21 at 08:57
  • Yeah done now .Kindly check it once please – Selva May 23 '21 at 09:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/232761/discussion-between-selva-and-willem-van-onsem). – Selva May 23 '21 at 09:11
  • @WillemVanOnsem Hi, i'm having similar issue i upgraded from django 1.9 to 3.2 with alot and alot of updates now it comes to this point that application is successfully running the server, but i get the Page not found on whatever url i put, seems like there's a disconnect between url configurations, any help is appericated – Habib Rehman Dec 07 '21 at 13:57