Как получить различные части url-адреса запроса колбы?
Я хочу определить, пришел ли запрос от localhost:5000
или foo.herokuapp.com
хоста и какой путь был запрошен. Как я могу получить эту информацию о запросе колбы?
3 ответа:
вы можете изучить url через несколько
Request
поля:пользователь запрашивает следующий URL:
http://www.example.com/myapplication/page.html?x=y
в этом случае значения вышеперечисленных атрибутов будут следующими:
path /page.html script_root /myapplication base_url http://www.example.com/myapplication/page.html url http://www.example.com/myapplication/page.html?x=y url_root http://www.example.com/myapplication/
вы можете легко извлечь часть узла с соответствующим шпагат.
еще пример:
запрос:
curl -XGET http://127.0.0.1:5000/alert/dingding/test?x=y
затем:
request.method: GET request.url: http://127.0.0.1:5000/alert/dingding/test?x=y request.base_url: http://127.0.0.1:5000/alert/dingding/test request.url_charset: utf-8 request.url_root: http://127.0.0.1:5000/ str(request.url_rule): /alert/dingding/test request.host_url: http://127.0.0.1:5000/ request.host: 127.0.0.1:5000 request.script_root: request.path: /alert/dingding/test request.full_path: /alert/dingding/test?x=y request.args: ImmutableMultiDict([('x', 'y')]) request.args.get('x'): y