tags:

views:

334

answers:

2

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?

A: 

A small conversation on case sensitive urls happened here. If you really want to do case insensitive urls, you could try using the poster's fix.

Adam
+10  A: 

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!-)

Alex Martelli
It worked.... Thank you very much... Can you suggest me good resources for learning regular expressions using python?
Software Enthusiastic
Alex Martelli