Madhav Parikh
Madhav Parikh

Reputation: 81

If condition not working in jinja in python flask

I need to bifurcate the side navigation bar in html via values parsed in python to jinja via if conditions but is not helping,so here is the sample code

I have tried from various sites but i am not able to get pass through this problem

JINJA/HTML CODE:

{% if account == 'admin' %}
  <h1>ADMIN</h1>
{% else }
  <h1>USER</h1>
{% endif %}

PYTHON CODE:

@app.route('/loginscr/', methods =['POST'])
def loginscr():
    username = request.form['username'] 
    password = request.form['password'] 
    cursor = connection.cursor()
    cursor.execute('Select * from auth_master where username = %s AND password = %s limit 1',(username,password))
    account = cursor.fetchone()
    print(username) 
    if account:
        print(account)
    return render_template('index.html', account = account)

Upvotes: 1

Views: 3142

Answers (1)

sumit gupta
sumit gupta

Reputation: 26

I think there is syntax error in your else statement. It should be like this:

{% if account == 'admin' %} 
    <h1>ADMIN</h1> 
{% else %}
    <h1>USER</h1>
{% endif %}

Upvotes: 1

Related Questions