Building a Python Flask application — Tutorial 03

  • URL: localhost:5000/
@app.route('/')
def index():
return 'Index Page'
  • URL: localhost:5000/hello
@app.route('/hello')
def hello_world():
return 'Hello, World'
@app.route('/user/<variable_name>')
def function_name(variable_name):
from flask import Flask
app = Flask(__name__)
@app
.route('/user/<username>')
def user_details(username):
return 'User name is %s' % username
from flask import Flask
app = Flask(__name__)
@app
.route('/user/<str: username>')
def user_details(username):
return 'User name is %s' % username
http://flask.pocoo.org/docs/1.0/quickstart/
<!DOCTYPE html><html lang="en">  <head>    <meta charset="UTF-8">    <title>Hello World</title>  </head>  <body>    <h1>Hello World</h1>  </body></html>
  • import render_template
  • return render_template(‘hello.html’)
from flask import Flaskfrom flask import render_templateapp = Flask(__name__)
@app.route('/')def hello_world(): return render_template('hello.html')if __name__ == '__main__': app.run()

--

--

Senior Software Engineer at Spades | LinkedIn: https://www.linkedin.com/in/sashini-hettiarachchi/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store