django urls without a trailing slash do not redirect django urls without a trailing slash do not redirect python python

django urls without a trailing slash do not redirect


Or you can write your urls like this:

(r'^login/?$', 'mySite.myUser.views.login')

The question sign after the trailing slash makes it optional in regexp. Use it if for some reasons you don't want to use APPEND_SLASH setting.


check your APPEND_SLASH setting in the settings.py file

more info in the django docs


This improves on @Michael Gendin's answer. His answer serves the identical page with two separate URLs. It would be better to have login automatically redirect to login/, and then serve the latter as the main page:

from django.conf.urls import patternsfrom django.views.generic import RedirectViewurlpatterns = patterns('',    # Redirect login to login/    (r'^login$', RedirectView.as_view(url = '/login/')),    # Handle the page with the slash.    (r'^login/', "views.my_handler"),)