#32710 closed Bug (wontfix)
static template tag converts '?' to '%3F'
Reported by: | Adrian Garcia | Owned by: | nobody |
---|---|---|---|
Component: | contrib.staticfiles | Version: | 3.1 |
Severity: | Normal | Keywords: | static template |
Cc: | Florian Apolloner | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
As the title suggests, the static template tag converts all question marks to '%3F' which will cause CSS and JS to fail to load.
Template code:
<script src="{% static 'bootstrap/js/bootstrap.bundle.min.js?test'%}"></script>
Output is:
<script src="/js/bootstrap.bundle.min.js%3Ftest"></script>
I followed the execution path and the replacement happens in django.utils.encoding.filepath_to_uri
when urllib.parse.quote
is called. I think '?' should be denoted as a safe character because otherwise, the function will replace it with a byte representation
Change History (6)
comment:1 by , 4 years ago
comment:2 by , 4 years ago
Description: | modified (diff) |
---|
comment:3 by , 4 years ago
Why do we *want* to convert '?' to '%3F'? The tests seem to indicate that this is by design.
comment:4 by , 4 years ago
Cc: | added |
---|---|
Component: | Template system → contrib.staticfiles |
Has patch: | unset |
Resolution: | → wontfix |
Status: | new → closed |
comment:5 by , 4 years ago
Then what's the current alternative? I need to timestamp my static files so I can force update them in the browser and the best way I've found to do that is to tack ?[timestamp]
on to the static import.
comment:6 by , 4 years ago
Personally I do not think there is a good reason to add a timestamp as query param. Cache busting can be done via hashed files and if you really must you can always write your own staticfiles backend. If you need help there please use the normal support channels (forum, django-users mailing list).
Proposed patch