flask guide python code example
Example 1: python basic flask app
# Imports necessary libraries
from flask import Flask
# Define the app
app = Flask(__name__)
# Get a welcoming message once you start the server.
@app.route('/')
def home():
return 'Home sweet home!'
# If the file is run directly,start the app.
if __name__ == '__main__':
app.run(Debug=True)
# To execute, run the file. Then go to 127.0.0.1:5000 in your browser and look at a welcoming message.
Example 2: flask tutorials
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World’
if __name__ == '__main__':
app.run()