烧瓶请求:确定确切路径,包括是否有问号 [英] Flask request: determine exact path, including if there is a question mark

查看:58
本文介绍了烧瓶请求:确定确切路径,包括是否有问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以确定请求到服务器的路径,包括是否包含问号?应用程序

Is there a way to determine what the path was requested to the server, including if it included a question mark? The application

from flask import Flask, Response, request

def root():
    return Response(
        f'full_path:{request.full_path} '
        f'path:{request.path} '
        f'query_string:{request.query_string} '
        f'url:{request.url}'
    )

app = Flask('app')
app.add_url_rule('/', view_func=root)

app.run(host='0.0.0.0', port=8081, debug=False)

总是导致

full_path:/? path:/ query_string:b'' url:http://localhost:8081/

如果要求

http://localhost:8081/?

http://localhost:8081/

在许多情况下,这似乎并不重要,但我正在进行具有多个重定向的身份验证流程,其中用户应以与开始时完全相同的URL结束.目前,我看不到任何方法来确保Flask能够做到这一点.

This may seem unimportant in a lot of cases, but I'm making an authentication flow with multiple redirections, where the user is meant to end up at the exact same URL as they started. At the moment, I can't see a way to ensure this happens with Flask.

推荐答案

除了您已经提到的字段外,"environ"字段中的值可能对您有用:

In addition to the fields you have already mentioned, Values in 'environ' field might be useful in your case:

def root():
    return Response(
        f'raw_uri:{request.environ["RAW_URI"]} '
        f'request_uri:{request.environ["REQUEST_URI"]}'
    )


输入:


Input:

http://localhost:8081/?

输出:

raw_uri:/?
request_uri:/?


输入:


Input:

http://localhost:8081/

输出:

raw_uri:/
request_uri:/

这篇关于烧瓶请求:确定确切路径,包括是否有问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆