diff options
| author | Simon Willison <simon@simonwillison.net> | 2008-07-02 08:32:55 +0000 |
|---|---|---|
| committer | Simon Willison <simon@simonwillison.net> | 2008-07-02 08:32:55 +0000 |
| commit | f918f9180f38451e3924fa04da453bb81a9dc6ed (patch) | |
| tree | 001ff05bf4c5707e7dc143dc72fb936bf2bbf5f6 | |
| parent | 2e5cc7413fdf0ee3cee92d855cf9b75999c8d79a (diff) | |
newforms-admin: custom URL handling in admin now redirects to add trailing slash if needed - this fixes several bugs that occurred when you navigated to an admin page and omitted the trailing slash.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/contrib/admin/sites.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/admin_views/tests.py | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 2ca5d99a4b..6aa65c2db3 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -100,6 +100,9 @@ class AdminSite(object): `url` is the remainder of the URL -- e.g. 'comments/comment/'. """ + if request.method == 'GET' and not request.path.endswith('/'): + return http.HttpResponseRedirect(request.path + '/') + # Figure out the admin base URL path and stash it for later use self.root_path = re.sub(re.escape(url) + '$', '', request.path) diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 788b16294b..98ccab65a5 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -74,7 +74,19 @@ class AdminViewPermissionsTest(TestCase): 'username': 'joepublic', 'password': 'secret'} + def testTrailingSlashRequired(self): + """ + If you leave off the trailing slash, app should redirect and add it. + """ + self.client.post('/test_admin/admin/', self.super_login) + request = self.client.get( + '/test_admin/admin/admin_views/article/add' + ) + self.assertRedirects(request, + '/test_admin/admin/admin_views/article/add/' + ) + def testLogin(self): """ Make sure only staff members can log in. |
