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['user_id'] = user['id']
        return redirect(url_for('index'))


return render_template('login.html')

My HTML code is:

{% extends 'layout.html' %}

{% block body %}


{% include 'includes/_messages.html %} Username Password Submit {% endblock %}

1 Answer 1


request.form[name] does not exist. use request.form.get(name). Note that i used () not [] as well as request.form.get(). If you have any other errors. Just check the /login code for refrence since that one is already built in, or it should be. speaking of which, why did you change it? what your register submission should do is link to register and in register(), your code should say:

if method == 'POST':
    # save account in database (note that this is pseudo code)
    return redirect("/login")
    return render_template("/register")

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .