Check if request is AJAX in Python(检查请求是否是 Python 中的 AJAX)
问题描述
有没有办法在 Python 中检查请求是否为 AJAX?
Is there a way to check if a request is AJAX in Python?
相当于 PHP 的 $_SERVER['HTTP_X_REQUESTED_WITH'] == 'xmlhttprequest'
?
The equivalent of PHP's $_SERVER['HTTP_X_REQUESTED_WITH'] == 'xmlhttprequest'
?
推荐答案
如果 AJAX 框架在其请求中设置 X-Requested-With 标头,那么您将能够使用该标头来检测 AJAX 调用.这取决于客户端框架.
If the AJAX framework sets the X-Requested-With header in its requests, then you will be able to use that header to detect AJAX calls. It's up to the client-side framework to do this.
获取 HTTP 标头取决于您选择的 Python 框架.在 Django 中,request
对象有一个 is_ajax
方法可以直接使用.
Getting hold of the HTTP headers depends on your Python framework of choice. In Django, the request
object has an is_ajax
method you can use directly.
这篇关于检查请求是否是 Python 中的 AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查请求是否是 Python 中的 AJAX


- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01