1# Extremely simple flask application, will display 'Hello World!' on the screen when you run it
2# Access it by running it, then going to whatever port its running on (It'll say which port it's running on).
3from flask import Flask
4app = Flask(__name__)
5
6@app.route('/')
7def hello_world():
8 return 'Hello, World!'
9
10if __name__ == '__main__':
11 app.run()
1from flask import render_template
2
3@app.route('/hello/')
4@app.route('/hello/<name>')
5def hello(name=None):
6 return render_template('hello.html', name=name)
1from flask import Flask
2from flask import render_template
3app = Flask(__name__)
4
5@app.route('/')
6def index():
7 return render_template("index.html") #if you want to render a .html file,
8 # import render_template from flask and use
9 #render_template("index.html") here.
10
11if __name__ == '__main__':
12 app.debug = True
13 app.run() #go to http://127.0.0.1:5000/ to view the page.
1from flask import Flask
2app = Flask(__name__)
3
4@app.route('/')
5def index():
6 return 'Flask'
1from flask import render_template
2
3@app.route('/hello/')
4@app.route('/hello/<name>')
5def hello(name=None):
6 return render_template('hello.html', name=name)
7
8---------------------------------------------------
9<!doctype html>
10<title>Hello from Flask</title>
11{% if name %}
12 <h1>Hello {{ name }}!</h1>
13{% else %}
14 <h1>Hello, World!</h1>
15{% endif %}
16