@bp.route("<STR_LIT>", methods=("<STR_LIT:GET>", "<STR_LIT:POST>"))<EOL>def register():
if request.method == "<STR_LIT:POST>":<EOL><INDENT>username = request.form["<STR_LIT:username>"]<EOL>password = request.form["<STR_LIT:password>"]<EOL>error = None<EOL>if not username:<EOL><INDENT>error = "<STR_LIT>"<EOL><DEDENT>elif not password:<EOL><INDENT>error = "<STR_LIT>"<EOL><DEDENT>elif db.session.query(<EOL>User.query.filter_by(username=username).exists()<EOL>).scalar():<EOL><INDENT>error = f"<STR_LIT>"<EOL><DEDENT>if error is None:<EOL><INDENT>db.session.add(User(username=username, password=password))<EOL>db.session.commit()<EOL>return redirect(url_for("<STR_LIT>"))<EOL><DEDENT>flash(error)<EOL><DEDENT>return render_template("<STR_LIT>")<EOL>
Register a new user.

    Validates that the username is not already taken. Hashes the
    password for security.