I've searched the forum and I haven't found the answer to this question. I'm frustrated because my code seems to match the tutorial exactly and yet it still doesn't work.
I am on Tango With Django section 4.5 and I am trying to set up the urls.
Here is the urls.py file in my project folder:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'tango_with_django.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^rango/', include('rango.urls')),
)
urls.py from 'rango' app folder:
from django.conf.urls import patterns, url
from rango import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'))
views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World")
When I run manage.py runserver, the error I get in browser is:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/
Using the URLconf defined in tango_with_django.urls, Django tried these URL patterns, in this order:
^admin/
^rango/
The current URL, , didn't match any of these.
Any help is greatly appreciated.
I think it's quite normal to have this problem. You need to manually navigate to
http://localhost:8000/rango
What this line is doing is that it tells your application if the url has rango/ in it, go to rango.urls to figure out what to do next!!!
The url you're looking at just now is
http://localhost:8000/
and as you can see it hasn't been defined in your url resolver. If you want your app to do something with the root urlhttp://localhost:8000/
then you need to add a line in your urls.py like thisHope this helps.