Issue
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'
]
Solution
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
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.