0
有沒有一種方法來識別驗證錯誤與包含多個表單的模板的哪個表單關聯?Django識別非字段驗證錯誤與哪個表單關聯
讓我來解釋一下這個場景。我有我的base.html文件
<div id="dialog1" class="window">
<form method="post" action="/accounts/login/?next=/IW/home" id='login-form' name=login-form>{% csrf_token %}
<div class="d-header">
{{ form.non_field_errors }}
<input type="text" name="username" id="id_username" value="" onclick="this.value=''"/><br/>
<input type="password" name="password" id="id_password" value="" onclick="this.value=''"/><br/>
<input type="hidden" name="login_form" value="1" />
<input type="submit" value="login" />
</div>
{% endif %}
</div>
</form>
</div>
<div id="mask"></div>
{% if form.non_field_errors %}
<script>
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
$('#mask').show();$('.window').show();
</script>
{% endif %}
像所有其他模板擴展的基礎上,只要有一個錯誤non_field錯誤,則登錄窗口彈出的HTML內登錄窗口彈出腳本。我只想在登錄表單提交時顯示登錄錯誤,而不是提交其他表單時出現非字段錯誤。
爲此,我需要確定form.something的名稱,像這樣{%ifequal form.form_name login_form%} - 顯示登錄錯誤。是否有可能?