【发布时间】:2017-08-01 16:56:29
【问题描述】:
我已经在 javascript 中动态创建了表单元素:
var selectform = document.createElement("form")
我在 selectform 中添加了其他输入元素和这些属性:
submitnselection.setAttribute('type',"submit");
submitnselection.setAttribute('value',"Submit");
submitnselection.setAttribute("name","submitnpage");
selectform.setAttribute("method", "post")
selectform.setAttribute = ("action", "/test")
"{% csrf_token %}";
在 HTML 中,添加 {% csrf_token %} 模板标签会起作用,但在这种 javascript 的情况下,我得到了 403 禁止错误:
CSRF 令牌丢失或不正确。
我找到了一些解决方案,但没有什么对我有用,有没有办法添加 {% csrf_token %} 以仅使用 Django、Javascript 和纯 Jquery 形成?另请注意,此脚本在 html 中,所以我认为 {% csrf_token %} 模板标签会起作用。
【问题讨论】:
标签: javascript jquery html django