检查请求的AJAX在Python [英] Check if request is AJAX in Python
问题描述
有没有一种方法来检查,如果一个请求是AJAX在Python?
Is there a way to check if a request is AJAX in Python?
的等效PHP的 $ _ SERVER ['HTTP_X_REQUESTED_WITH'] =='xmlhtt prequest
?
推荐答案
如果在AJAX框架将X-要求,凭借其请求头,那么你就可以使用这个标题来检测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中,要求
对象有一个<一个href="https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.Htt$p$pquest.is_ajax"><$c$c>is_ajax$c$c>方法就可以直接使用。
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.
这篇关于检查请求的AJAX在Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!