Hello friends. The question is certainly trivial. Going through the django documentation lesson:

There is an error when going to: http://127.0.0.1:8000/polls/

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/polls/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^polls/ ^S [name='index'] ^polls/ ^(?P<question_id>[0-9]+)/$ [name='detail'] ^polls/ ^(?P<question_id>[0-9]+)/results/$ [name='results'] ^polls/ ^(?P<question_id>[0-9]+)/vote/$ [name='vote'] ^admin/ The current URL, polls/, didn't match any of these. 

my ~ mysite \ polls \ urls.py:

 from django.conf.urls import url from . import views urlpatterns = [ url(r'^S', views.index, name='index'), url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'), url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'), url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'), ] 

~ 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/', include(admin.site.urls)), ] 

~ mysite \ polls \ views.py:

 from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the polls") def detail(request, question_id): return HttpResponse("You are looking at question %s." % question_id) def results(request, question_id): response = "You are looking at the results of question %s" return HttpResponse(response % question_id) def vote(request, question_id): return HttpResponse("You are voting on question %s." % question_id) 

At the same time on other url:

 .../polls/5/ .../polls/5/results/ .../polls/5/vote/ 

proceeds without error. All perfectly. What could be the reason for this behavior? I would be grateful for the advice.

    1 answer 1

    You here

     url(r'^S', views.index, name='index'), 

    It is worth S instead of $ .

    • thanks @Vadim. Inattentively copied an example. How to check such syntax errors in the editor? - ufo
    • It was a completely correct code, this is nothing to check - andreymal
    • Yes, you have been commented rightly, this is not a syntax error, but a semantic error, no editor, alas, will understand what you meant, not what you wrote. - Vadim Shender