I am trying a simple Flask tutorial I found on-line. Here is the code:

from flask import Flask, jsonify
from flask_cors import CORS

# configuration
DEBUG = True

# instantiate the app
app = Flask(__name__)

# enable CORS

# sanity check route
@app.route('/ping', methods=['GET'])
def ping_pong():
    return jsonify('pong!')

if __name__ == '__main__':

In Spyder if I run the File, it works fine. However, I would like to be able to debug and execute statements as I select them. When I select the entire contents and execute (via the interactive console), I get the error below. Is there a way to make this work?

Serving Flask app "__main__" (lazy loading)
 Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 Debug mode: on
 Running on (Press CTRL+C to quit)
 Restarting with stat
/opt/local/anaconda3/bin/python: can't find '__main__' module in ''
An exception has occurred, use %tb to see the full traceback.

1 Answers

Syed Zubair Ahamed On

you can probable try this code below scenario

from werkzeug.debug import DebuggedApplication

def create_app(): # Insert whatever else you do in your Flask app factory.

if app.debug:
    app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True)

return app

this will enable debugging your application

for complete source code with examples please check below link https://github.com/nickjj/build-a-saas-app-with-flask