python – Flask redirect not working after post request with apache

I started learning python and flask recently and I’m trying to deploy my site today. I used this tutorial: orials/how-to-deploy-a-flask-application-on-an-ubuntu-vps. Everything worked, but when I try to log in or register, the server can’t render the site that I want it to render. This is how it works when I run the server on my computer: https://youtu.be/eQYGyJBM42g. And this is on my ubuntu vps: https://youtu.be/zsUUCQ02mqU.

This is my auth.py file which handles login, logout and registration:

@auth.route('/login', methods=('GET', 'POST'))
def login():
if request.method == 'POST':
    email = request.form.get('email')
    password = request.form.get('password')

    db = connect_database()
    cur = db.cursor(dictionary=True)
    sql = "SELECT * FROM users WHERE email = %s"
    val = (email, )
    cur.execute(sql, val)
    user = cur.fetchone()
    cur.close()
    if not user:
        flash('K tomuto emailu neexistuje žádný účet!', category='error')
        return redirect(url_for('views.home'))
    if check_password_hash(user('heslo'), password):
        flash('Jsi přihlášen/a!', category='success')
        session('loggedin') = True;
        session('id') = user('userId')
        session('email') = user('email')
        return redirect(url_for('views.home'))
    else:
        flash('Špatný email nebo heslo. Zkus to znovu.', category='error')

return render_template("login.html")


@auth.route('/logout')
def logout():
if 'loggedin' in session:
    session.pop('loggedin', None)
    session.pop('id', None)
    session.pop('email', None)
return redirect(url_for('auth.login'))


@auth.route('/sign-up', methods=('GET', 'POST'))
def signup():
if request.method == 'POST':
    email = request.form.get('email')
    first_name = request.form.get('firstName')
    password1 = request.form.get('password1')
    password2 = request.form.get('password2')
    
    db = connect_database()
    cur = db.cursor(dictionary=True)
    sql = "SELECT * FROM users WHERE email = %s"
    val = (email,)
    cur.execute(sql, val)
    user = cur.fetchone() 
    if user:
        flash('Email již existuje!', category='error')
    elif not re.match(r'^(a-z0-9)+(._)?(a-z0-9)+(@)w+(.)w{2,3}$', email):
        flash('Nevalidní email!', category='error')
    elif len(first_name) < 2:
        flash('Jméno musí mít alespoň 2 znaky!', category='error')
    elif password1 != password2:
        flash('Hesla se neshodují!', category='error')
    elif len(password1) <= 5:
        flash('Heslo musí mít alespoň 5 znaků.', category='error')
    else:
        password = generate_password_hash(password1, method='sha256')
        sql = "INSERT INTO users (jmeno, email, heslo) VALUES (%s, %s, %s)"
        val = (first_name, email, password, )
        cur.execute(sql, val)
        db.commit()
        flash('Účet byl úspěšně vytvořen!', category='success')
        sql = "SELECT * FROM users WHERE email = %s"
        val = (email, )
        cur.execute(sql, val)
        user = cur.fetchone()
        session('loggedin') = True
        session('id') = user('userId')
        session('email') = user('email')
        cur.close()
        return redirect(url_for('views.home'))

return render_template("sign_up.html", user=current_user)

And this is my .wsgi error log: https://pastebin.com/GHxbszZm

And tried searching for any solutions but couldn’t find any. Thanks to everyone for any help.