Flask webview does not show HTML

Hi, I am a teacher, one of my students has an error that I cannot debug.

Using my own repl account this works and produces “hello world” in web view.

from flask import Flask

app = Flask(__name__)


# basic route
@app.route("/")
def root():
    return '<h1 style="color:red;">Hello World</h1>'


if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=8080)

console out put is:

* Serving Flask app 'main'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:8080
 * Running on http://172.31.196.99:8080
Press CTRL+C to quit
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 174-275-786
172.31.196.1 - - [20/Jul/2023 04:04:16] "OPTIONS * HTTP/1.1" 404 -
172.31.196.1 - - [20/Jul/2023 04:04:16] "GET / HTTP/1.1" 200 -
172.31.196.1 - - [20/Jul/2023 04:04:16] "GET / HTTP/1.1" 200 -

Now when the student runs the exact same code, the console output is:

* Serving Flask app 'main'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:8080
 * Running on http://172.31.196.13:8080
Press CTRL+C to quit
 * Restarting with stat
Python 3.10.8 (main, Oct 11 2022, 11:35:05) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Could anyone help me debug this? We have already tried this in several new student repls with no success. Thanks in advance.

did they fork the repl, or just copy the code? if so, try having your students fork your repl and see if the error pertains

Try removing

From the app.run line. IIRC, the debugger causes issues.

3 Likes

Excellent, removing the debugger option gets it going - thanks so much!

1 Like

Happy to help where I can!

1 Like

But why is this issue happening ? It’s still working in the repls those were created earlier. How to debug now?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.