0

I want the output inside my variable msg4, which is linked to my html file, to have green color if an else statement occurs. I can't do it in render_template because if the else statement does not occur, the font color of the message will be red, as I wrote on my css file. It would be great if I could change my css file just when this else statement is called, because this msg4 would be the final output then. Here is the else statement with the message I want to give green color:

        else:
            # If the form data is valid, now update user table
            cursor.execute("UPDATE user SET FirstName = %s, LastName = %s, Email = %s WHERE UID = %s", (firstName, lastName, email, id))
            mysql.connection.commit()
            msg4 = 'Changes successfully saved!'

1 Answer 1

2

Instead of changing the css, you can change the color in html. You can use jinja2 templates to pass the color value from python to html.

Html

style='color: {{msg4color}}'

Then in python set the color value to red or green depending on the else statement. Then pass it on to the render template

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.