Page 404 error after running Django server

Question:

I have just started learning django and was trying to make a smartnotes App project by following a course.
I updated the setting.py file to add website into Instaled_Apps. Then have written a function named home in views.py
Finally I added it’s entry into urls.py fie
"welcome.html is insdie homeApp/templates/home directory"
But when I run the server, I am getting following error on webpage:

views.py

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


# Create your views here.

def home(request):
    return render(request, 'home/welcome.html', {})

settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # apps that I created
    'home',
]

urls.py

from django.contrib import admin
from django.urls import path
from django.urls import path
from home import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('home', views.home),
]

welcome.html

    <title>
        welcome Page
    </title> </head> <body>
        <h1>Hello world !!!</h1>
        <h2>this is my first ever django project....</h2> </body> </html> ``` 



> **error its show is**
> 
> Page not found (404) Request Method:  GET Request URL:
>   http://127.0.0.1:8000/
> 
> Using the URLconf defined in smartappProject.urls, Django tried these
> URL patterns, in this order:
> 
>     admin/
>     home
> 
> The empty path didn’t match any of these.
Asked By: Hafiz

||

Answers:

Look at your urlpatterns:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('home', views.home),
]

You haven’t set the path for real "home" page, which should be "". Change it to:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home),
]

And you will be fine. The first argument in parenthesis is real "value" that you need to provide just after the domain (http://localhost:8000/ with local service).

Answered By: NixonSparrow
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.