You need to save the code in a file first, and then run it from the command line. Just typing it in the interactive prompt will not work.
Here is what a minimal Flask application looks like:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World'
if __name__ == '__main__':
app.run()
Save this code to a file (for example, server.py
) and then run it with python server.py
.