Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 为单个表单禁用csrf令牌_Django_Csrf - Fatal编程技术网

Django 为单个表单禁用csrf令牌

Django 为单个表单禁用csrf令牌,django,csrf,Django,Csrf,我有一个html表单,可以从另一个位置向django web应用程序发送post数据。如何禁用该特定表单或请求的csrf令牌检查?您可以将csrf\u豁免装饰器添加到视图中 实例 您可以在视图中添加csrf\u豁免decorator 实例 你在评论中提到了Crispyform。如果您使用的是FormHelper函数,那么解决方案是更改为设置disable_csrf属性 class ExampleForm(forms.Form): def __init__(self, *args, **kwarg

我有一个html表单,可以从另一个位置向django web应用程序发送post数据。如何禁用该特定表单或请求的csrf令牌检查?

您可以将
csrf\u豁免
装饰器添加到视图中

实例
您可以在视图中添加
csrf\u豁免
decorator

实例
你在评论中提到了Crispyform。如果您使用的是FormHelper函数,那么解决方案是更改为设置disable_csrf属性

class ExampleForm(forms.Form):
def __init__(self, *args, **kwargs):
    super(ExampleForm, self).__init__(*args, **kwargs)
    self.helper = FormHelper(self)
    self.helper.disable_csrf = True
有关更多信息,请参见此处:

如果这给您带来任何麻烦,还可以查看他们的test.py文件:

具体而言:

def test_disable_csrf(self):
    form = TestForm()
    helper = FormHelper()
    helper.disable_csrf = True
    html = render_crispy_form(form, helper, {'csrf_token': _get_new_csrf_key()})
    self.assertFalse('csrf' in html)

你在评论中提到了Crispyform。如果您使用的是FormHelper函数,那么解决方案是更改为设置disable_csrf属性

class ExampleForm(forms.Form):
def __init__(self, *args, **kwargs):
    super(ExampleForm, self).__init__(*args, **kwargs)
    self.helper = FormHelper(self)
    self.helper.disable_csrf = True
有关更多信息,请参见此处:

如果这给您带来任何麻烦,还可以查看他们的test.py文件:

具体而言:

def test_disable_csrf(self):
    form = TestForm()
    helper = FormHelper()
    helper.disable_csrf = True
    html = render_crispy_form(form, helper, {'csrf_token': _get_new_csrf_key()})
    self.assertFalse('csrf' in html)

不是一个视图,只是一个表单。是一个向导表单(crispyform),我只想禁用其中的第一个表单。您应该更新您的问题并包含代码片段。不是视图,只是一个表单。是一个向导表单(crispyform),我只想禁用第一个表单。您应该更新您的问题并包含代码片段。