我已经浏览过并找到了与我类似的帖子,但我所拥有的一切似乎都处于有序状态,所以我很难过。
我有一个javascript片段,允许用户选择两个建筑物中的一个,然后根据使用的建筑物给出不同的选项集。这是使用帖子提交按钮。到处都说它与{%csrf_token%}有关,但我已将其包含在表单中,并在settings.py中有中间件。如果它有所不同,那么在同一页面上也会有一个获取请求。
表格
<form id="formname" name="formname" method="POST" action="">{% csrf_token %}
<table width="50%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="41%" align="right" valign="middle">Category :</td>
<td width="59%" align="left" valign="middle">
<select name="category" id="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);">
<option value="">Select Building</option>
<option value="Marcus">Marcus</option>
<option value="Pettit">Pettit</option>
</select>
</td>
</tr>
<tr>
<td align="right" valign="middle">Location :</td>
<td align="left" valign="middle">
<script type="text/javascript" language="JavaScript">
document.write('<select name="subcategory"><option value="">Select Location</option> </select>')
</script>
<noscript>
<select name="subcategory" id="subcategory">
<option value="">Select Location</option>
</select>
</noscript>
</td>
</tr>
<tr>
<td>
<td align="left" valign="middle">
<input value="Inventory Safety Log" type="submit">
</td>
</tr>
</table>
</form>
Javascript
<script language="javascript" type="text/javascript">
function dropdownlist(listindex) {
document.formname.subcategory.options.length = 0;
switch (listindex) {
case "Marcus":
document.formname.subcategory.options[0] = new Option("Select Location", "");
document.formname.subcategory.options[1] = new Option("Chemical Room", "Chemicals");
document.formname.subcategory.options[2] = new Option("Supply Room", "Supplies");
document.formname.subcategory.options[3] = new Option("Gas Storage G205", "G205");
document.formname.subcategory.options[4] = new Option("In-Organic Sub Fab G230", "G230");
document.formname.subcategory.options[5] = new Option("Gas Bunker", "Gas Bunker");
break;
case "Pettit":
document.formname.subcategory.options[0] = new Option("Select Location", "");
document.formname.subcategory.options[1] = new Option("Chemical Room", "Chemicals");
document.formname.subcategory.options[2] = new Option("Supply Room", "Supplies");
document.formname.subcategory.options[3] = new Option("Utility Chase #19", "19");
document.formname.subcategory.options[4] = new Option("Utility Chase #25", "25");
document.formname.subcategory.options[5] = new Option("Utility Chase #29", "29");
document.formname.subcategory.options[6] = new Option("Utility Chase #30", "30");
document.formname.subcategory.options[7] = new Option("Utility Chase #36", "36");
document.formname.subcategory.options[8] = new Option("Utility Chase #44", "44");
document.formname.subcategory.options[9] = new Option("Gas Cage", "Gas Cage");
document.formname.subcategory.options[10] = new Option("Bunker", "Bunker");
break;
}
return true;
}
</script>
感谢您提供任何意见,建议,提示或见解。
主要问题是,当我尝试发布表单时,它会将我带到csrf验证失败页面。