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 , 9 years ago
Type: | Uncategorized → Bug |
---|
follow-up: 3 comment:2 by , 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: | Unreviewed → Accepted |
Version: | 1.9a1 → 1.8 |
comment:3 by , 9 years ago
Replying to timgraham:
Maybe it would work to use
get_script_prefix()
for the site url ifself.site_url == '/'
inAdminSite.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.
IMHO we don't need self.site_url == '/'
check since site_url
is used only once and get_script_prefix()
returns /
for sites hosted at root.
comment:4 by , 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:6 by , 9 years ago
Needs documentation: | set |
---|
Maybe it would work to use
get_script_prefix()
for the site url ifself.site_url == '/'
inAdminSite.each_context()
.