[Python] Create a minimal website in Python using the Flask Microframework

How to install Flask Use Flask to create a minimal website Build routes in Flask to respond to website endpoints Use Variable Rules to pass parts of the URL to your functions as keyword parameters

Install:

pip install Flask

 

Development Mode:

run_local.sh:

#!/bin/bash

export FLASK_APP=app.py
export FLASK_DEBUG=1
flask run

 

app.py:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello world!'

@app.route('/foo/')
def foo():
    return 'The foo page'

@app.route('/bar')
def bar():
    return 'The bar page'

@app.route('/hello/')
@app.route('/hello/<name>')
def say_hello(name=None):
    return 'Hello {}'.format(user)

 

posted @ 2018-04-30 15:58  Zhentiw  阅读(197)  评论(0编辑  收藏  举报