Reputation: 3
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
here is the screenshot of the error page
'''
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
mysite\urls.py:
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),
]
polls\urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]
views:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
Upvotes: 0
Views: 283
Reputation: 6825
As things are set up at the moment you would need to navigate to:
http://127.0.0.1:8000/polls
Your 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.
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 polls.urls
regardless.
Upvotes: 1