On 27 March 2011 14:51, Pascal Germroth <funkyco...@gmail.com> wrote: > Hi, > >> urlpatterns = patterns('', >> url(r'^admin/', include(admin.site.urls)), >> (r'^', include('apps.textcontent.urls')), >> ) > >> when i pass: /admin/ all is ok, but when I pass /admin - >> apps.textcontent.urls are executed, but why? > > Well because the URL pattern is a regular expression that is matched against > the URL, and you explicitly stated that there has to be a / at the end. > > Change it to url(r'^admin/?',…) and it will work both with '/admin' and > '/admin/'. > > But: this is bad URL etiquette. You should choose a schema (/ or not) and > stick with it. Even better: create a view that matches the opposite of your > chosen schema and permanently redirects to the correct URL (or enable > normalisation in your webserver, that would be easier)
Good news, Django already provides a way to do this. See APPEND_SLASH[1] setting and CommonMiddleware[2]. [1]: http://docs.djangoproject.com/en/1.3/ref/settings/#append-slash [2]: http://docs.djangoproject.com/en/1.3/ref/middleware/#django.middleware.common.CommonMiddleware -- Łukasz Rekucki -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.