Case insensitive urls for Django?

前端 未结 5 1840
野的像风
野的像风 2020-12-04 22:14

It seems by default django\'s url solver perform case sensitive search for solving url and differentiate between \'/Login\' and \'login\'. My url patterns are as follows.

5条回答
  •  孤街浪徒
    2020-12-04 22:41

    Just put (?i) at the start of every r'...' string, i.e.:

    urlpatterns = patterns('',
    (r'^(?i)admin/(.*)', admin.site.root),
    (r'^(?i)static/(?P.*)$', 'django.views.static.serve',
        {'document_root': settings.STATIC_DOC_ROOT, 'show_indexes': True}),
    (r'^(?i)login/$', 'django.contrib.auth.views.login'),
    (r'^(?i)logout/$', do_logout),
    )
    

    to tell every RE to match case-insensitively -- and, of course, live happily ever after!-)

提交回复
热议问题