basic website flask python code example
Example 1: python basic flask app
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Home sweet home!'
if __name__ == '__main__':
app.run(Debug=True)
Example 2: html for basic flask home page python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, World!"
@app.route('/welcome')
def welcome():
return render_template('welcome.html')
if __name__ == '__main__':
app.run(debug=True)
Example 3: basic flask app python
import os
try:
from flask import *
except:
os.system("pip3 install flask")
from flask import *
app = Flask(__name__)
@app.route("/")
def index():
return "<h1>Hello World</h1>"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080, debug=False)