1

im trying to get my url named, so it can be reversed in my django app.

mysite/urls.py:

urlpatterns = patterns('',
                   # Examples:
                   url(r'^$', 'myapp.views.redirect_to_home'),
                   url(r'^admin/', include(admin.site.urls)),
                   url(r'^myapp/', include('myapp.urls')),)

myapp/urls.py

urlpatterns = patterns('',
                   url(r'(?i)^$', views.redirect_to_home),
                   url(r'(?i)^Login/$', views.home, name="home"),
                   url(r'(?i)^Logout/$', views.logout_user, name="logout_user"),)

be minded that i had purpusly added the '(?i)^' in the beggining of every regex, to make the urls in-case sensitive.

but, having this string '(?i)^' had made my reverse function to fail saying

Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['myapp/(?i)^Login/$']

after trying to remove the (?i)^ , i noticed the reverse succeeds.

What can i do to make my urls in-case sensitive, and still reversable?

Thanks.

user1612927
  • 95
  • 1
  • 5
  • They're **not meant** to be case insensitive. Why would you want this? Anyway - the `(?i)` has to be at the **very start** of a regex in Python builtin `re`... it can't be used halfway through/switched off later... If you really wanted to do this, you're probably better off looking at some middleware which deliberately lower-cases the path (or possibly lower case it at your front-end server), then stick to lower case url matching in your routing – Jon Clements May 10 '14 at 16:04
  • why shouldn't they? i dont want anyone to try accessing my website through mistakenly capitalized url, and get an 404.. is it really not common? – user1612927 May 10 '14 at 16:49
  • Most users will hit your home page or have book marked your own internal links... look at the middleware or the frontend solutions I suggested - no idea which is more appropriate for you – Jon Clements May 10 '14 at 16:51
  • 1
    I Will certainly will, even so, i tried moving the (?i) to the begining of mysite/urls.py urls, and still it doesnt work with the same error. meaning although they located in the very begining of the string it still couldnt match the pattern. why? – user1612927 May 10 '14 at 16:55

0 Answers0