600521c3d0bb07273.jpg_fo742.jpg

# -*- coding: utf-8 -*-
#pip install Flask-BasicAuth


from flask import Flask
from flask_basicauth import BasicAuth

app = Flask(__name__)

app.config['BASIC_AUTH_USERNAME'] = 'test'
app.config['BASIC_AUTH_PASSWORD'] = 'test1'

# app.config['BASIC_AUTH_FORCE'] = True  # 全站

basic_auth = BasicAuth(app)


@app.route('/')
def index():
    return "hello world"


@app.route('/secret')
@basic_auth.required
def secret():
    return "hello world1 "


if __name__ == '__main__':
    app.run()


发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code