from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world")
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),
]
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.
You forgot to say what is going wrong... I guessing you're getting a:
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:
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...