How can I preserve the python '%' character when adding to a string that will be run as html?
Here is some possibly important background info: I am parsing .js paths server-side in python, adding them to the context object. My goal is to reflectively load js packages based on the url endpoint used by the client.
@api_view(["GET"])
def home(request, path="tutorial"):
return render(request, "template.html", context={
"path" : "{% static '"+ path +".js' %}"
})
The issue I've run into is that the '%' character does not convert correctly, as you can see from the server log:
[23/Apr/2022 11:05:40] "GET /%7B/%%20static%20'tutorial.js'%20/%%7D HTTP/1.1" 404 2574
I know that '%' is used by python for string manipulation and therefore is added to strings as a multi-char code, but what I can't figure out is how to add a literal %. I've tried '/%', r'', and b'' variations, .encode() too, but none of them change the output.
Here is what is being run client side:
<script type="text/javascript" src="{{path}}"></script>
I've tested everything else, and it all works perfectly. I just can't get python to send html friendly '%'s!