Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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 Adrian Garcia)

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:2 by Adrian Garcia, 4 years ago

Description: modified (diff)

comment:3 by Adrian Garcia, 4 years ago

Why do we *want* to convert '?' to '%3F'? The tests seem to indicate that this is by design.

comment:4 by Mariusz Felisiak, 4 years ago

Cc: Florian Apolloner added
Component: Template systemcontrib.staticfiles
Has patch: unset
Resolution: wontfix
Status: newclosed

Yes, this is an intended behavior, please see Florian's comment and PR.

comment:5 by Adrian Garcia, 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 Florian Apolloner, 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).

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