Opened 9 years ago

Closed 9 years ago

#25519 closed Bug (fixed)

"View Site" in admin shows wrong URL if site is not hosted at root

Reported by: Dheerendra Rathor Owned by: nobody
Component: contrib.admin Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In django-admin VIEW_SITE should redirect to base of hosted site. If site is not hosted at the root but at some other location, then still VIEW_SITE redirects to absolute root of the site.

Example:
Suppose site is hosted at http://example.com/mysite/ and I'm using SCRIPT_NAME HTTP header in my proxy server. {% url 'some_url' %} results into /mysite/some/url/ which is correct. But site_url in django admin is hardcoded to /.

Here is the relevant code snippet from django.contrib.admin.sites.AdminSite

# URL for the "View site" link at the top of each admin page.
site_url = '/'

Change History (7)

comment:1 by Dheerendra Rathor, 9 years ago

Type: UncategorizedBug

comment:2 by Tim Graham, 9 years ago

Easy pickings: unset
Summary: VIEW_SITE in django-admin shows wrong URL if site is not hosted at root!"View Site" in admin shows wrong URL if site is not hosted at root
Triage Stage: UnreviewedAccepted
Version: 1.9a11.8

Maybe it would work to use get_script_prefix() for the site url if self.site_url == '/' in AdminSite.each_context().

in reply to:  2 comment:3 by Dheerendra Rathor, 9 years ago

Replying to timgraham:

Maybe it would work to use get_script_prefix() for the site url if self.site_url == '/' in AdminSite.each_context().

I replaced 'site_url': self.site_url, in my django.contrib.admin.sites.AdminSite#each_context to 'site_url': get_script_prefix(), and then I got expected result.

Version 0, edited 9 years ago by Dheerendra Rathor (next)

comment:4 by Tim Graham, 9 years ago

The if statement is needed because if someone customizes site_url, then we don't want to ignore the value that they set.

comment:5 by Tim Graham, 9 years ago

Has patch: set

comment:6 by Tim Graham, 9 years ago

Needs documentation: set

comment:7 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 59e85f0:

Fixed #25519 -- Made the admin "View site" link point to sites running on a subpath.

Used request.METASCRIPT_NAME as the site_url if it hasn't been
customized from the default value of '/'.

Note: See TracTickets for help on using tickets.
Back to Top