Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
47,899
Solution 1
Your url conf regex is incorrect, you have to use $
instead of %
.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
The $
acts as a regex flag to define the end of the regular expression.
Solution 2
urlpatterns = [path('', views.index, name='index'), ]
Author by
HLH
Updated on January 02, 2021Comments
-
HLH over 3 years
I know this question has been asked before, but I haven't found an answer that solves my situation.
I'm looking at the Django tutorial, and I've set up the first URLs exactly as the tutorial has it, word for word, but when I go to http://http://localhost:8000/polls/, it gives me this error:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^polls/ ^% [name='index'] ^admin/ The current URL, polls/, didn't match any of these.
I'm using Django 1.10.5 and Python 2.7.
Here is the code I have in relevant url and view files:
In mysite/polls/views.py:
from django.shortcuts import render from django.http import HttpResponse # Create your views here. def index(request): return HttpResponse("Hello, world. You're at the polls index.")
In mysite/polls/urls.py:
from django.conf.urls import url from . import views urlpatterns = [ url(r'^%', views.index, name='index'), ]
In mysite/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), ]
What's going on? Why am I getting 404s?
-
HLH over 7 yearsUgh, can't believe I missed that. Thank you.
-
Coliban almost 5 yearsThen the original django documentation is broken where it is desrcibed in a wrong way: Writing your first Django app, part 1
-
CodingMatters over 4 yearsDjango version 1.x to 2.x changed from url to path. I'm new to Django, landed here while diagnosing errors following this tut/demo. thecodinginterface.com/blog/django-auth-part1 I should have followed the official django tut first :) Using the URLconf defined in django_survey.urls, Django tried these URL patterns, in this order: blah. dropping link below to help alternate universe version of me time warp. consideratecode.com/2018/05/02/…
-
Naman Bansal almost 4 yearsyou don't need to use Regex links in Django 3.0. I am still getting this error. Any suggestions?
-
v1k45 almost 4 yearsYou can use the path function to define a wildcard url
path('', views.index, name='index'),
-
Mike1982 almost 3 years@v1k45 that was my problem as well. Your solution fixed it for Django 3.1