Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000

Question:

I got the following error whenever I run the project:


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

admin/
playground/
The empty path 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 project(storefront) urls.py:

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

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

]

Here is playground urls.py code:

from django.urls import path, include
from . import views

 #urlConfig
 urlpatterns=[
    path('hello/', views.say_hello)
 ]

Here is views.py file:

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

# Create your views here.
def say_hello(request):
    return HTTPResponse('Hello world')

Here is my project settings:

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'playground'
 ]
Asked By: Cecil Bennett

||

Answers:

You got this error because there is no any empty route in your urls.py.

try this, you will get that page:

localhost:8000/playground/hello/

OR

make it empty.

path('', include('playground.urls'))

also make empty route in app urls.py file:

path('', views.say_hello)

And visit to your browser and type:

localhost:8000

Simply it will display that page.

Hope you understand

Answered By: Manoj Tolagekar

project urls.py:

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

]

app urls.py:

urlpatterns=[
    path('', views.say_hello)
 ]

This will work for Empty route.

Answered By: Hemal Patel
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.