亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Django CSRF 在使用 Dynamic Formset 和 Django Formtools

Django CSRF 在使用 Dynamic Formset 和 Django Formtools

青春有我 2022-09-06 17:57:34
我正在使用Django formttools來創建一個多步驟向導。在其中一個表單中,我有一個問題選項,用戶需要根據需要添加盡可能多的問題。我已經通過Django Dynamic Formset實現了動態表單集,但是盡管我的模板中有{%csrf_token%},但我仍然遇到CSRF問題。這是我的模板: {% block content %}  <p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>  <form action="" method="post" enctype="multipart/form-data" id="job-question">{% csrf_token %}    <table>    {{ wizard.management_form }}{% if wizard.form.forms %}    {{ wizard.form.management_form }}    {% for form in wizard.form.forms %}        {{ form }}    {% endfor %}{% else %}    {{ wizard.form }}{% endif %}</table>{% if wizard.steps.prev %}<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">{% trans "first step" %}</button><button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button>{% endif %}<input type="submit" value="{% trans "submit" %}"/></form><script type="text/javascript" src="{% static 'js/jquery-min.3.4.1..js' %}"></script><script type="text/javascript" src="{% static 'js/jquery.formset.js' %}"></script><script type="text/javascript">    $(function() {        $('#job-question').formset();    })</script>{% endblock %}
查看完整描述

1 回答

?
牛魔王的故事

TA貢獻1830條經驗 獲得超3個贊

我設法通過將每個表單及其id傳遞給動態表單集JS函數來處理這個問題。通過這種方式,驗證是完全完成的。


查看完整回答
反對 回復 2022-09-06
  • 1 回答
  • 0 關注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號