Reputation: 347
I have started learning Django and I was watching this lecture (till starting 20 minutes) and following the instructions but I am getting the error as :
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/hello
Using the URLconf defined in lecture3.urls, Django tried these URL patterns, in this order:
admin/
The current path, hello, 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.
After running
python3 manage.py runserver
My settings.py file in "lecture3" app is :
# Application definition
INSTALLED_APPS = [
'hello',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
and some other content.
views.py file in "hello" app is :
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
return HttpResponse("Hello World!")
urls.py file in "hello" app is :
from django.urls import path
from . import views
urlpatterns=[
path("",views.index, name="index")
]
urls.py file in "lecture3" app is :
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('/hello/', include('hello.urls'))
]
I have checked similar questions here but my problem was not resolved. Can anyone please tell why I am getting this error. Any help would be appreciated.
Upvotes: 0
Views: 306
Reputation: 2919
Given:
...
path('/hello/', include('hello.urls'))
...
Remove the first slash from the path:
...
path('hello/', include('hello.urls'))
...
Then you need to access it with a trailing slash /
as follows http://127.0.0.1:8000/hello/
Or with Django's conventions, use APPEND_SLASH=True
in your settings.py
so accessing http://127.0.0.1:8000/hello
will redirect to http://127.0.0.1:8000/hello/
Upvotes: 1