Forums

What is wrong with my code?

Can someone see anything I'm doing wrong? Here is meaningful part of template code, which on its own is well working:

<form method="POST">
            <input type="number" name="hour_input"><input type="number" name="min_input"><input type="number" name="sec_input"><br>
            <button type="submit">Activate timer</button>
        </form>
        <p>{{message}}</p>

Here is my app code:

from flask import Flask, request, render_template
import time
app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])

def timer():
    msg = 'Time is up!'
    if request.method == 'POST':
        hour_entry = request.form['hour-input']
        min_entry = request.form['min_input']
        sec_entry = request.form['sec_input']
        try:
            timer_time = int(hour_entry.get())*3600 + int(min_entry.get())*60 + int(sec_entry.get())
        except:
            return render_template('index.html', message = 'Error')
        if timer_time >0:
            hour = 0
            min = 0
            sec = 0
            while timer_time >= 0:
                min, sec = divmod(timer_time,60)
                if min > 60:
                    hour, min = divmod(min,60)
                hour.set(hour)
                min.set(min)
                sec.set(sec)
                time.sleep(1)
                timer_time -= 1
            return render_template('index.html', message=msg)


if __name__ == '__flask_app__':
    app.run()

It is not showing any errors in console, but the site is still not working and showing the "Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."

What errors do you see in your logs? (link to logs are available on the "Web" page on PythonAnywhere).