-1

I am new to flask and trying to deploy my webapp. I'm getting a 500 Internal Server Error on "/login" page. I don't know what's wrong with my code. The app runs fine on localhost. But when I deployed it on pythonanywhere it is throwing the error.

(I'm using sqlalchemy with sqlite and here is the '/login' and '/' route code snippet)

@app.route('/')
def home():
    if not session.get('logged_in'):
        return render_template('homepage.html')

    else:
        return render_template('quiz.html')

@app.route('/login', methods=['POST'])
def do_admin_login():
    Session = sessionmaker(bind = engine)
    s = Session()
    global USERN
    global PASSWD
    POST_USERNAME = str(request.form['username']).lower()
    USERN = POST_USERNAME   
    POST_PASSWORD = str(request.form['password'])
    PASSWD = POST_PASSWORD
    query = s.query(User).filter(User.username.in_([POST_USERNAME]),User.password.in_([POST_PASSWORD]))
    result = query.first()
    if result:
        session['logged_in'] = True
    else:
        return 'wrong credentials'

    return home()

1 Answers1

2

I don't know whether you copied your code the wrong way but you need to change the lines of code below

@app.route('/')
def home():
if not session.get('logged_in'):
    return render_template('homepage.html')

else:
    return render_template('quiz.html')

To this

@app.route('/')
def home():
    if not session.get('logged_in'):
        return render_template('homepage.html')
    else:
        return render_template('quiz.html')

Because that could as well be causing the error and you could as well in your app configuration on pythonanywhere set debug=True to see what exactly is causing the error

kellymandem
  • 1,709
  • 3
  • 17
  • 27