Forums

Page not found (404)

Hi I am new to programming. I am following Django official tutorial along with PythonAnywhere Tutorial. I followed each step and managed to see the page with little rocket and message saying "The install worked successfully! Congratulations!".

Then I went further by 1) Creating the Polls app

python manage.py startapp polls

2) Write your first view

polls/views.py
    from django.http import HttpResponse


    def index(request):
        return HttpResponse("Hello, world. You're at the polls index.")

In the polls/urls.py file include the following code:

polls/urls.py
    from django.urls import path

    from . import views

    urlpatterns = [
        path('', views.index, name='index'),
    ]

mysite/urls.py

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

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

3) Instead of this command >> $ python manage.py runserver , I reloaded the page from the web app configuration page and got the following result:-

Page not found (404) Request Method: GET Request URL: http://bnyrj.pythonanywhere.com/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: polls/ 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.

Please advise me what went wrong?

You don't have a url defined for /. You have /admin and /polls.

I have followed the official django tutorial with Pythonanywhere tutorial. Can you tell me how to define the URL. What did I miss from the tutorial?

You're just going to the wrong url. The url you want is not /, it;s /polls

Please let me know how I can fix it. In which file I have to edit it?

Hi Glenn,

Please advise where I have to make the correction.

I followed the the tutorials exactly, but couldnt figure out what is the problem.

The problem is that you're going to the wrong URL. Your polls app is at http://bnyrj.pythonanywhere.com/polls/

Thanks Glenn

could you tell me how you solve the problem?thanks. I meet the same error

could you tell me how you solve the problem?thanks. I meet the same error

thank you . i solved.

OK, glad you worked it out!

How did you solve the problem?

Another way it worked for me was by redirecting from the main page by adding this lines to the project urls.py

urls.py

from django.views.generic.base import RedirectView

urlpatterns = [

path('', RedirectView.as_view(url='/polls/')), ...

That's a neat solution!

how you solved this issue

What's the exact problem that you're having?

how to solve the above error, same I also got it. Please any can help me?

what is the error that you are seeing?

i could not get output pls help

What output?

[formatted by admin]

Page not found (404)
Request Method: GET
Request URL:    http://sravankodem.pythonanywhere.com/polls
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

admin/
The current path, polls, 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 need to configure urls for your app. Looks like endpoint polls is not set up.

I'm seeing the same "Page not found" error, but as I'm looking through the discussion I don't see any solutions. I followed the tutorial and I'm going to the correct URL. Any suggestions?

What url is that? (you can contact us at support@pythonanywhere.com if you don't want to share it here on public forums)

I found the error. I rebuilt the entire project locally and it worked fine. It turned out that my urls.py file didn't get updated. All good now. Thanks.

Glad you solved that!