Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive urls for Django?

Tags:

python

django

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.

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

Can anyone please guide me, how to make django urls case insensitive?

like image 393
Software Enthusiastic Avatar asked Oct 04 '09 04:10

Software Enthusiastic


1 Answers

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

urlpatterns = patterns('', (r'^(?i)admin/(.*)', admin.site.root), (r'^(?i)static/(?P<path>.*)$', '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!-)

like image 137
Alex Martelli Avatar answered Oct 10 '22 08:10

Alex Martelli