我在所有静态页面中都有登录表单。我在我的项目中启用了csrf中间件。现在,当用户提交从http形式静态页面出现错误,当从非安全页面发布到安全页面时,django csrf失败
csrf verification failed
有没有一种方法,以确保跨站点验证,非scure发布到安全的网页,即使?
我想既不添加scrf exempt装饰器也不将页面更改为https。
这是我的模板:
<form action='{{login_url}}' method = 'post'>
{% csrf_token %}
<div class="searchbox login">
<input autocomplete="off" id="id_fakeusername" type="text" name="fakeusername" maxlength="100" value='Email' style="color: #727272" onfocus="$('#id_fakeusername').hide();$('#id_username').show();
$('#id_username').focus();" />
<input autocomplete="off" type='text' id="id_username" type="text" name="username" maxlength="100" style="display: none" value='' onblur="if ($('#id_username').attr('value') == '') {$('#id_username').hide();$('#id_fakeusername').show();}" />
</div>
<div class="searchbox login">
<input autocomplete="off" id="id_fakepassword" type="text" name="fakepassword" maxlength="50" style="color: #727272" value='Password' onfocus="$('#id_fakepassword').hide(); $('#id_password').show(); $('#id_password').focus();" />
<input autocomplete="off" type='password' id="id_password" name="password" type="text" style="display: none" value='' onblur="if ($('#id_password').attr('value') == '') {$('#id_password').hide();$('#id_fakepassword').show();}" />
</div>
{% block nativewin %}
<div class="loginbut"><input type="submit" border="0" title="Login" value="Login" /></div>
{% endblock nativewin %}
</form>
我与我的模板代码 –
是的,我按照所有CSRF步骤更新的问题,我可以看到,当我从一个安全的页面张贴工作。但它不工作时从http发布到https页面 –
只是为了理解你的用例..为什么你想在表单提交中从http切换到https?您可以通过http提供的页面或https提供的页面呈现,提交和验证您的表单。 –