Loading django/contrib/admin/sites.py +6 −1 Original line number Diff line number Diff line Loading @@ -306,11 +306,16 @@ class AdminSite(object): """ Returns a dictionary of variables to put in the template context for *every* page in the admin site. For sites running on a subpath, use the SCRIPT_NAME value if site_url hasn't been customized. """ script_name = request.META['SCRIPT_NAME'] site_url = script_name if self.site_url == '/' and script_name else self.site_url return { 'site_title': self.site_title, 'site_header': self.site_header, 'site_url': self.site_url, 'site_url': site_url, 'has_permission': self.has_permission(request), 'available_apps': self.get_app_list(request), } Loading docs/ref/contrib/admin/index.txt +9 −0 Original line number Diff line number Diff line Loading @@ -2513,6 +2513,15 @@ Templates can override or extend base admin templates as described in The URL for the "View site" link at the top of each admin page. By default, ``site_url`` is ``/``. Set it to ``None`` to remove the link. For sites running on a subpath, the :meth:`each_context` method checks if the current request has ``request.META['SCRIPT_NAME']`` set and uses that value if ``site_url`` isn't set to something other than ``/``. .. versionchanged:: 1.10 The ``SCRIPT_NAME`` support described in the previous paragraph was added. .. attribute:: AdminSite.index_title The text to put at the top of the admin index page (a string). By default, Loading docs/releases/1.10.txt +3 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,9 @@ Minor features :mod:`django.contrib.admin` ^^^^^^^^^^^^^^^^^^^^^^^^^^^ * ... * For sites running on a subpath, the default :attr:`URL for the "View site" link <django.contrib.admin.AdminSite.site_url>` at the top of each admin page will now point to ``request.META['SCRIPT_NAME']`` if set, instead of ``/``. :mod:`django.contrib.admindocs` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Loading tests/admin_views/test_adminsite.py +5 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,11 @@ class SiteEachContextTest(TestCase): self.assertEqual(ctx['site_url'], '/') self.assertEqual(ctx['has_permission'], True) def test_each_context_site_url_with_script_name(self): request = RequestFactory().get(reverse('test_adminsite:index'), SCRIPT_NAME='/my-script-name/') request.user = self.u1 self.assertEqual(site.each_context(request)['site_url'], '/my-script-name/') def test_available_apps(self): ctx = self.ctx apps = ctx['available_apps'] Loading Loading
django/contrib/admin/sites.py +6 −1 Original line number Diff line number Diff line Loading @@ -306,11 +306,16 @@ class AdminSite(object): """ Returns a dictionary of variables to put in the template context for *every* page in the admin site. For sites running on a subpath, use the SCRIPT_NAME value if site_url hasn't been customized. """ script_name = request.META['SCRIPT_NAME'] site_url = script_name if self.site_url == '/' and script_name else self.site_url return { 'site_title': self.site_title, 'site_header': self.site_header, 'site_url': self.site_url, 'site_url': site_url, 'has_permission': self.has_permission(request), 'available_apps': self.get_app_list(request), } Loading
docs/ref/contrib/admin/index.txt +9 −0 Original line number Diff line number Diff line Loading @@ -2513,6 +2513,15 @@ Templates can override or extend base admin templates as described in The URL for the "View site" link at the top of each admin page. By default, ``site_url`` is ``/``. Set it to ``None`` to remove the link. For sites running on a subpath, the :meth:`each_context` method checks if the current request has ``request.META['SCRIPT_NAME']`` set and uses that value if ``site_url`` isn't set to something other than ``/``. .. versionchanged:: 1.10 The ``SCRIPT_NAME`` support described in the previous paragraph was added. .. attribute:: AdminSite.index_title The text to put at the top of the admin index page (a string). By default, Loading
docs/releases/1.10.txt +3 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,9 @@ Minor features :mod:`django.contrib.admin` ^^^^^^^^^^^^^^^^^^^^^^^^^^^ * ... * For sites running on a subpath, the default :attr:`URL for the "View site" link <django.contrib.admin.AdminSite.site_url>` at the top of each admin page will now point to ``request.META['SCRIPT_NAME']`` if set, instead of ``/``. :mod:`django.contrib.admindocs` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Loading
tests/admin_views/test_adminsite.py +5 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,11 @@ class SiteEachContextTest(TestCase): self.assertEqual(ctx['site_url'], '/') self.assertEqual(ctx['has_permission'], True) def test_each_context_site_url_with_script_name(self): request = RequestFactory().get(reverse('test_adminsite:index'), SCRIPT_NAME='/my-script-name/') request.user = self.u1 self.assertEqual(site.each_context(request)['site_url'], '/my-script-name/') def test_available_apps(self): ctx = self.ctx apps = ctx['available_apps'] Loading