Page 404 error after running Django server

4,737 views
Skip to first unread message

Deepti sharma

unread,
May 4, 2020, 6:09:51 PM5/4/20
to Django users
Hi, I have just started learning django and was trying to make a meeting planner project y folllowing a course.
I updated the setting.py file to add website into Instaled_Apps. Then have written a function named welcome in views.py
Finally I added it's entry into urls.py fie
But when I run the server, I am getting following error on webpage:

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/

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

  1. admin/
  2. welcome.html/

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.


Can someone please help me with this? I am stuck.



This is my code:  (meeting_planner/website/views.py):

from django.shortcuts import render
from django.http import HttpRequest
# Create your views here.

def welcome(request):
return HttpRequest("Welcome to the Meeting Planner Website!")

(meeting_planner/meeting_planer/urls.py):
from django.contrib import admin
from django.urls import path
from website import views
from django.conf.urls import url,include

from website.views import welcome

urlpatterns = [
path('admin/', admin.site.urls),
path('welcome.html', welcome)
]

Amitesh Sahay

unread,
May 4, 2020, 6:12:55 PM5/4/20
to django...@googlegroups.com
There are lots of issues with urls.py
Please go through the django documents on how to write urls.py


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3d38a2c2-3449-4c2f-839e-244b9295f55d%40googlegroups.com.

franz ulenaers

unread,
May 4, 2020, 6:19:12 PM5/4/20
to django...@googlegroups.com
path('welcome.html', welcome)
should be :
path('', welcome)


Op 4/05/2020 om 20:11 schreef 'Amitesh Sahay' via Django users:

Franz Ulenaers

unread,
May 4, 2020, 6:21:31 PM5/4/20
to Django users
pleae change your urls.py as follow

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


Op maandag 4 mei 2020 20:09:51 UTC+2 schreef Deepti sharma:

Deepti sharma

unread,
May 4, 2020, 6:26:45 PM5/4/20
to django...@googlegroups.com
Hi, I did replace it with: path('',welcome)
But it's still no working:

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/welcome

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

  1. admin/

The current path, welcome, 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.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.


--
Regards
Deepti Sharma
Blog: https://deepti96.wordpress.com/
Github: https://github.com/dsdeeptisharma
Gitlab: https://gitlab.com/u/dsdeepti
"Great works are not performed by strength but by perseverance"

R D Saini

unread,
May 4, 2020, 6:38:29 PM5/4/20
to django...@googlegroups.com
path("welcome/",views.welcom),

Deepti sharma

unread,
May 4, 2020, 6:43:49 PM5/4/20
to django...@googlegroups.com
@rdsai...@gmail.com 
I updated it with: path("welcome/",views.welcome),
But  no success.

Error at http://127.0.0.1:8000/welcome :

TypeError at /welcome/

__init__() takes 1 positional argument but 2 were given
Request Method:GET
Request URL:http://127.0.0.1:8000/welcome/
Django Version:3.0.5
Exception Type:TypeError
Exception Value:
__init__() takes 1 positional argument but 2 were given
Exception Location:C:\Users\deeptish\PycharmProjects\GettingStartedDjango\meeting_planner\website\views.py in welcome, line 6
Python Executable:C:\Users\deeptish\PycharmProjects\GettingStartedDjango\venv\Scripts\python.exe
Python Version:3.7.7
Python Path:
['C:\\Users\\deeptish\\PycharmProjects\\GettingStartedDjango\\meeting_planner',
 'C:\\Users\\deeptish\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
 'C:\\Users\\deeptish\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',
 'C:\\Users\\deeptish\\AppData\\Local\\Programs\\Python\\Python37\\lib',
 'C:\\Users\\deeptish\\AppData\\Local\\Programs\\Python\\Python37',
 'C:\\Users\\deeptish\\PycharmProjects\\GettingStartedDjango\\venv',
 'C:\\Users\\deeptish\\PycharmProjects\\GettingStartedDjango\\venv\\lib\\site-packages']
Server time:Mon, 4 May 2020 18:40:54 +0000

Traceback Switch to copy-and-paste view

  • C:\Users\deeptish\PycharmProjects\GettingStartedDjango\venv\lib\site-packages\django\core\handlers\exception.py in inner
    1.             response = get_response(request)
  • C:\Users\deeptish\PycharmProjects\GettingStartedDjango\venv\lib\site-packages\django\core\handlers\base.py in _get_response
    1.                 response = self.process_exception_by_middleware(e, request)
  • C:\Users\deeptish\PycharmProjects\GettingStartedDjango\venv\lib\site-packages\django\core\handlers\base.py in _get_response
    1.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)



Amitesh Sahay

unread,
May 4, 2020, 6:46:33 PM5/4/20
to django...@googlegroups.com

Amitesh Sahay

unread,
May 4, 2020, 6:48:09 PM5/4/20
to django...@googlegroups.com
Please import HttpResponse , 

HttpRequest will not work

Jorge Gimeno

unread,
May 4, 2020, 6:50:25 PM5/4/20
to django...@googlegroups.com
I just realized that the view is returning an HttpRequest.  It should be an HttpResponse object (and the import should be changed to bring that object in as well).

-Jorge

Nomeh Uchenna Gabriel

unread,
May 4, 2020, 7:06:20 PM5/4/20
to Django users
Hi! you're just visiting a different url from what you specified in your "urls.py" file.

look closely at the routes "django" is telling you that it tried:

[admin/, welcome.html/]

... these are truly the two paths that you specified, why on earth are you trying to visit a non-existing path(http://127.0.0.1:8000/)

... kindly visit (http://127.0.0.1:8000/welcome.html)

and face your next error in the "views.py" file ('HttpRequest' instead of 'HttpResponse')

Deepti sharma

unread,
May 4, 2020, 7:28:18 PM5/4/20
to django...@googlegroups.com
Thanks everyone.
I updated HttpRequest with HttpResponse.
Then in urls.py:
I did:
path(‘’, views.welcome)

Its working now

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages