You can create a div below the box that receives the input for the credential/credentials that where in valid:
In the HTML:
<style>
.invalid_input{
width:100px;
height:20px;
border-radius:4px;
background-color:red;
color:white;
}
</style>
<html>
<form action="/login" method="post" class="card-title">
<input class="form-control" name="username" placeholder="Username" type="text"/>
<div class='invalid_input'>{{message_username}}</div>
<div class='spacer' style='height:10px;'></div>
<input class="form-control" name="password" placeholder="Password" type="password"/>
<div class='invalid_input'>{{message_password}}</div>
<div class='spacer' style='height:10px;'></div>
<button class="btn" type="submit">Log In</button>
</form>
</html>
Then, in the app (utilizing placeholder lookup functions for username and password):
@app.route('/login', methods = ['GET', 'POST'])
def login():
if flask.request.method == 'POST':
username = flask.request.form['username']
password = flask.request.form['password']
u_flag, p_flag = is_valid_username(username), is_valid_password(password)
if not u_flag or not p_flag:
return flask.render_template('login.html', message_username = '' if u_flag else 'Invalid Username', message_password = '' if p_flag else 'Invalid Password'
return flask.render_template('login.html', message_username = '', message_password = '')