小编Afs*_*ali的帖子

如何在Flask中为多个功能使用相同的路由

我目前正在使用python3Flask; 我使用相同的路由定义了两个函数。-如何index2打印。

from flask import Flask, request, make_response

app = Flask(__name__)

@app.route('/')
def index():
    if request.authorization and request.authorization.username == 'user1' and request.authorization.password == 'pass1':
        return '<h1>You are logged in</h1>'
    return make_response('Could not verify!', 401, {'WWW-Authenticate' : 'Basic realm="Login Required"'})

@app.route('/')
def index2():
    print('In Index 2')

if __name__ == '__main__':
    app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)

flask python-3.x

6
推荐指数
1
解决办法
3649
查看次数

如何将控制台输出放入txt文件中(使用python Flask服务器)

假设我有一个服务器代码,当调用函数 savePersonList() 时,控制台上打印的结果应保存到文本文件中。

#server coding

app = Flask(__name__)
def allowed_file(filename):
  # this has changed from the original example because the original did not work for me
    return filename[-3:].lower() in ALLOWED_EXTENSIONS


@app.route('/', methods=['GET', 'POST']) #integrate code below function
def upload_file(): 

    if request.authorization and request.authorization.username == 'user1' and request.authorization.password == 'pass2': #login code line
        if request.method == 'POST':
            print("This is a post Request \n\n")
            file = request.files['file']
            if file and allowed_file(file.filename):
                print("File Sent is valid \n\n")
                print('**found file', file.filename)
                filename = secure_filename(file.filename) …
Run Code Online (Sandbox Code Playgroud)

flask python-3.x

4
推荐指数
1
解决办法
4372
查看次数

标签 统计

flask ×2

python-3.x ×2