Flask request: determine exact path, including if there is a question mark

后端 未结 1 747
南笙
南笙 2021-01-22 11:28

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, Respon         


        
相关标签:
1条回答
  • 2021-01-22 12:06

    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/?
    

    Output:

    raw_uri:/?
    request_uri:/?
    

    Input:

    http://localhost:8081/
    

    Output:

    raw_uri:/
    request_uri:/
    
    0 讨论(0)
提交回复
热议问题