Django tutorial HTTP Error 404

49 views
Skip to first unread message

Paweł Balawender

unread,
Mar 26, 2017, 10:54:22 AM3/26/17
to Django users
Hi

I'm a Django newbie on Windows and try to follow its official tutorial. I've done everything - as I think - completely fine, but at the last step I get a 404 Error, more precisely, that:

Page not found (404)

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

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

  1. ^polls/
  2. ^admin/

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


My directories are laid out like that:

#venv - directory of my virtual environment
venv\
testico\
mysite\
 __pycache__
__init__.py
settings.py
urls.py
wsgi.py 
polls\
__pycache__ 
migrations
 __init__, admin, apps, models, test - .py 
 urls.py
views.py 
db.sqlite3
manage.py  
#virtual environment files and directories below
Include, Lib, Scripts, pyvenv.cfg

 where testico\mysite\urls.py is just copypasted from tutorial's page, so:
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]

and testico\polls\urls.py is copypasted too, so:
from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$', views.index, name='index'),
]


 views is a short code, copied too:
from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse


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


Nothing could help, so, as you've seen higher, I've just copied everything from the official website.
Here is what do I do at command prompt:


and in my web browser, g chrome:


I have no idea what to do :/ I've read at least 5 answers to problems like mine on stackoverflow, but their solves dont solve that. Can you tell me why doesn't it work? I tried to run it outside of that venv directory, but it changes nothing.



Melvyn Sopacua

unread,
Mar 26, 2017, 11:32:17 AM3/26/17
to django...@googlegroups.com

On Sunday 26 March 2017 07:41:06 Paweł Balawender wrote:

 

> I'm a Django newbie on Windows and try to follow its official tutorial

> everything - as I think - completely fine

 

Almost. You're told to test runserver *before* creating the app. This is because the "it worked" page is a little magic that depends on DEBUG=True and only the admin urlpatterns registered.

 

As soon as you add more urls the magic stops working and since you did not define a homepage url, it is a genuine 404.

 

--

Melvyn Sopacua

ludovic coues

unread,
Mar 26, 2017, 11:56:45 AM3/26/17
to django...@googlegroups.com
This might be the most often asked question on this mailing list.

I'm pretty sure the code is perfectly fine, but you missed a little
step in the tutorial.
The third line of the error message is saying you opened http://127.0.0.1:8000/
The "Write your first view" chapter finish with "Go to
http://localhost:8000/polls/ "
That's why you get an error.
> --
> 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 post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7352927.CGXvrrnOJ1%40devstation.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages