Opened 10 years ago
Last modified 5 years ago
#25598 closed New feature
support for SCRIPT_NAME for static tag and FileField.url — at Initial Version
| Reported by: | Dheerendra Rathor | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.staticfiles | Version: | dev |
| Severity: | Normal | Keywords: | script_name, static_url, media_url |
| Cc: | kottenator@… | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
By default, static tag just appends STATIC_URL in the path. When running on subpath it results in incorrect static url.
This problem can be solved with appending SCRIPT_NAME in to SCRIPT_URL in settings.py
This can be easily added into default django static tag and django.contrib.staticfiles tag as following:
def render(self, context):
url = self.url(context)
# Updating url here with request.META['SCRIPT_NAME']
if self.varname is None:
return url
context[self.varname] = url
return ''
On more research I found that FileSystemStorage and StaticFilesStorage ignores script_name as well.
We might have to do a lot of changes but I think it's worth the efforts.