'("Django tried these URL patterns... The empty path didn't match any of these.") How to fix "Page not found (404)" error

I am using the visual studio code for the basic Django project and whenever I try to run the server it gives the error

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

login/ admin/ 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.

Whereas I write the code correctly

landing app folder views file code:

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

# Create your views here.

def loginpage (request):

  return render (request, 'login.html')

landing app file urls.py code

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

urlpatterns = [
    path('login/',views.loginpage, name="login" ),

landing app file login.html code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
</head>
<body>
    <h1> Login </h1>
</body>
</html>
     

main project urls.py file code

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

urlpatterns = [
     path('login/',include('landing.urls')),
    path('admin/', admin.site.urls),
]

Please help me regarding this.



Solution 1:[1]

try changing

from. import views

to

from . import views

Solution 2:[2]

Instead of this

urlpatterns = [
    path('login/',include('landing.urls')),
    path('admin/', admin.site.urls),
]

Try this

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SagaS
Solution 2 Kathir