[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)

猜你喜欢

转载自www.cnblogs.com/Answer1215/p/8973838.html
今日推荐