Why does a URL containing "/" after "$" return a page error error (404)

I have a problem with Django url patterns.

When I add '/' to the end of the index URL, the page returns 404 error (Page not found), and if I remove '/' from the end of the URL, the page will work fine.

The problem is not reproducing with the url for the admin page, can someone explain what is happening?

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$/',index),
]
+4
source share
4 answers

$: represents the end of the string, so there is no way for char living after that.

Matches the end of a line or immediately before a new line at the end of a line

^ , ^$ urls.py Django: URL-, /, Django .

+4

url django.conf.urls package

$ , char url.

+2

, django urls:

'$': , regex

'^': , url

0

$ url :

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^/$',index),
]
-1

Source: https://habr.com/ru/post/1686802/


All Articles