I have been following along with the Django tutorial for the poll app. I keep getting a 404 error when heading to the site. I have checked quite a few questions for this problem but I wasn’t able to find a solution
''' Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^polls/ ^admin/ The empty path didn’t match any of these. '''
my code is as follows
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), ]
from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index') ]
from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the polls index.")
How to not get the error:
As things are set up at the moment you would need to navigate to:
Why does it work this way
ROOT_URLCONF is currently set to
mysite.url.py (as it should be). This means that this is where django looks to resolve your request. It looks through each path in turn. If it matches
polls, it will then look at all the urls in
include('polls.urls'), but it needs to match that first polls bit before looking further.
How can I fix it?
One thing you could do is this:
urlpatterns = [ url(r'', include('polls.urls')), url(r'^admin/', admin.site.urls), ]
That way, django will look at