Hi,
I have a django-csp configuration problem linked to my use of inline css in a template.
In my template I have :
<div class="bg-green-800" style="width:{{ resultats_votes|get:candidat.id|get:'Excellent'|get:'percentage' }}%" nonce={{request.csp_nonce}}> </div>
The aim is to generate results bars dynamically.
{{request.csp_nonce}}
doesn’t do anything. with a ‘print’ in ‘views.py’ I get the value, and the same applies if I put {{request.csp_nonce}}
outside the <div>
arguments.
{{ results_votes|get:candidate.id|get:‘Excellent’|get:‘percentage’ }}
doesn’t display anything when django-csp is activated either. The bars remain empty.
Using dedicated CSS classes seems complicated because the size of each piece of the bar can be any value from 1 to 100.
the only thing that doesn’t cause an error is to use ‘unsafe-inline’ in ‘settings.py’ for CSP_STYLE_SRC_ATTR.
I’ve tried a decorator on my view but I must have the wrong syntax - it has no effect.
@csp_update(CSP_STYLE_SRC_ATTR=[‘’self‘’, ‘https://*.umami.is’, ‘unsafe-inline’])
or @csp_update({‘style-src-attr’: ‘unsafe-inline’})
would you have an idea to help me solve this problem and avoid using unsafe-inline?
Thanks