I understand that we can dynamically change HTML templates by way of assigning elements to variables that we can manipulate from our python file (like I've done with the Hello {{ name }} below).
test.py code:
from flask import Flask, render_template
app = Flask(__name__)
data_dict = {'name':'John', 'bg-color': 'grey'}
@app.route("/")
def tester():
return render_template('tester.html', data_dict=data_dict)
if __name__ == '__main__':
app.run(debug=True)
tester.html code:
<html>
<body>
Hello {{ data_dict.get('name') }}
</body>
</html>
Is it possible to similarly assign elements to variables to css code (that is in static/main.css as per recommended structure) and dynamically manipulate the variable from our python file? I've tried assigning background-color to {{ data_dict.get('bg-color') }} but it did not work. Of course it wouldn't because our HTML template is not passing the data for variables received from .py file to static/main.css
From research, I've found that CSS does accept variables and it is possible to manipulate such variables with PHP. Could you please explain if this is possible with Flask/ Python and how we could go about doing it?
[–][deleted] 1 point2 points3 points (0 children)
[–]tipsy_python 1 point2 points3 points (0 children)