I'm currently trying to implement code to ensure that once a user has registered, they can then log in. However, when I click the /login link I get an Internal Server Error. In CS50 IDE I get this message "jinja2.exceptions.TemplateSyntaxError: unexpected char "'" at 76", which is the "If error is None" line. Help please?
At the moment my code is thus:
User log in
@app.route('/login', methods =['GET', 'POST']) def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
error = None
user = db.execute('SELECT * FROM user WHERE username = ?', (username,)).fetchone()
if user is None:
error = 'Incorrect username.'
elif not check_password_hash(user['password'], password):
error = 'Incorrect password.'
if error is None:
session.clear()
session['user_id'] = user['id']
return redirect(url_for('index'))
flash(error)
return render_template('login.html')
My HTML code is:
{% extends 'layout.html' %}
{% block body %}