KamilO
KamilO

Reputation: 3

First view in DJANGO tutorial -> Page not found (404)

I was doing tutorial "Writing your first Django app, part 1" and I got stuck in "Write your first view". I have fulfil all instructions regardings files. When I go to http://127.0.0.1:8000/ then I can see "The install worked successfully! Congratulations!" but if I go to http://localhost:8000/polls/ then I see:

Page not found (404) Request Method: GET Request URL: http://localhost:8000/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.

In this case according instructions I should see "Hello, world. You're at the polls index". I attached 2 files content and 2 interesting screens (why does it emphasize?).

views.py

from django.http import HttpResponse


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

urls.py

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

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

I was looking answer in Stack Overflow (also in hints) or YouTube but unfortunately without success. Interesting but in another computer it works, but on my laptop not.

Upvotes: 0

Views: 179

Answers (2)

KamilO
KamilO

Reputation: 3

Subject closed. Solution -> Bad configuration urls.py file in mysite and polls. Check content both files in tutorial context.

Upvotes: 0

Emad G
Emad G

Reputation: 53

So you are doing the URLS incorrectly, or partially at least.
You need to create another app in django called polls:

python manage.py startapp polls

Then in the polls/urls.py file, include an extension for /polls, that references your view in polls/view.py:

urlpatterns = [
path('/polls', views.<view-name>, name='Polls URL')
]

Then it should work, otherwise you are doing something wrong and need to elaborate on our problem.

Note that Django's DEBUG should be True when developing at all times, so you can see the full error log. DEBUG=FALSE is used if you have a webapp public (aka deployed/in production.

Upvotes: 1

Related Questions