小编Jos*_*eph的帖子

(仍然)获取RuntimeError:在请求上下文之外工作。尝试app.app_context()时

from flask import Flask, request
app = Flask(__name__)

@app.route('/post/', methods=['GET', 'POST'])
def update_post():
    # show the post with the given id, the id is an integer
    postId = request.args.get('postId')
    uid = request.args.get('uid')
    return postId, uid

def getpostidanduid():
    with app.app_context():
        credsfromUI = update_post()
        app.logger.message("The postId is %s and uid is %s" %(request.args.get('postId'), request.args.get('uid')))
        ## Prints 'The post id is red and uid is blue'\
    return credsfromUI

print(getpostidanduid())

if __name__ == '__main__':
    # This is used when running locally. Gunicorn is used …
Run Code Online (Sandbox Code Playgroud)

python request flask

3
推荐指数
1
解决办法
2875
查看次数

标签 统计

flask ×1

python ×1

request ×1