Noobie question, can't get url request to work, 404

1,698 views
Skip to first unread message

ahic...@tamu.edu

unread,
Jul 5, 2017, 5:27:04 PM7/5/17
to Django users
So I literally just started django, I know 0 about backend dev, but im going through the djangobook tutorial (also, please excuse me if I use the wrong syntax). He shows us how to get content to show up on our temporary domain (a simple Hello World).

The hello world setup looks like so, with the file named views.py, located in the same directory as urls.py

from django.http import HttpResponse

def hello(request):
return HttpResponse("Hello world")

And the urls.py file looks like this

from django.conf.urls import url
from django.contrib import admin

from mysite.views import hello

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

I feel like somethings wrong with the path, or something like that? I'm kinda of clueless at this point though, I've been working on it for a while. I don't even know how to go about de-bugging, since this is vastly different from coding a simple "get all the odd numbers from a list" problem.

Thanks

johnf

unread,
Jul 5, 2017, 5:36:59 PM7/5/17
to django...@googlegroups.com

to be honest I haven't used Django in a while so take what I'm saying as wrong - but shouldn't the url be

url(r'hello/$', views.hello, name='hello'),

Not sure you need "^" although I doubt it hurts.

Johnf

--
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/7c751df1-c209-455c-bf83-f5fa2ddf3d8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alceu Rodrigues de Freitas Junior

unread,
Jul 5, 2017, 5:38:24 PM7/5/17
to django...@googlegroups.com

You forgot to say what is going wrong... I guessing you're getting a:

Page not found (404)

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

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

  1. ^admin/
  2. ^hello/

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.

The error message says a lot already: by the urls.py, your defining your view "hello" to be in http://127.0.0.1:8000/hello.

Django will not assume anything to your hostname and port number, but when you run it with "./manage.py runserver" you get a tip about:

~/django/noobie$ ./manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

July 05, 2017 - 21:32:06
Django version 1.11.1, using settings 'noobie.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Not Found: /
[05/Jul/2017 21:32:12] "GET / HTTP/1.1" 404 2019
Not Found: /favicon.ico
[05/Jul/2017 21:32:12] "GET /favicon.ico HTTP/1.1" 404 2070
Not Found: /favicon.ico
[05/Jul/2017 21:32:12] "GET /favicon.ico HTTP/1.1" 404 2070
[05/Jul/2017 21:32:18] "GET /hello HTTP/1.1" 301 0
[05/Jul/2017 21:32:18] "GET /hello/ HTTP/1.1" 200 11
[05/Jul/2017 21:32:33] "GET /hello/ HTTP/1.1" 200 11
Performing system checks...


ahic...@tamu.edu

unread,
Jul 5, 2017, 5:58:06 PM7/5/17
to Django users
oh wow that was it, i wasnt reading the instructions correctly, i clearly said to go to /hello. Sorry about that, and thanks!
Reply all
Reply to author
Forward
0 new messages