I have a flexbox with a number of shapes:
The background color initially is white, set by a static css file, and changes based on a calculated score from the survey when the results page is entered. I can do that with if statements but it is rather inelegant since each area would require its own set of if statements:
<style>
{% if shade == 1 %}
div.item_leadership {
background-color: rgb(255,0,0);}
{% elif shade == 2 %}
div.item_leadership {
background-color: rgb(255,255,0);}
{% elif shade == 3 %}
div.item_leadership {
background-color: rgb(0,255,0);}
{% endif %}
</style>
I would like to simply pass the color as a variable so I could use something like:
div.item_leadership {
background-color: {{ color }};}
via:
color = "red" #Some Variable to set color to red, yellow or green
return render(request, "ISO22301/results.html",context, color)
where “red” would in the final code be a variable set by the score. I used red just to test using a variable in the HTML file to override the static file background color. Instead of rendering ISO22301/results.html it POSTs the data but saves the HTML code to a file.
By looking at the file it downloads it is returning the proper HTML for the ISO22301/results.html page but is not using the variable to apply the new background color; instead something triggers a d/l of the HTML code:
<style>
div.item_leadership {
background-color: ;}
</style>
Static File relevant code:
.item_leadership, .item_context, .item_policy, .item_planning, .item_support, .item_operation, .item_management, .item_improvement {
width: 8vw;
height: 14vh;
padding: 10px;
align-content: center;
background-color: white;
border: 2px solid black;
display: inline-block;
vertical-align: middle;
text-align: center;
font-size: 2vh;
border-radius: 15px;
box-sizing: border-box;
}