gpt4 book ai didi

javascript - 未提交单个复选框表单。提交时还会收到 MultiValueDictKeyError

转载 作者:太空宇宙 更新时间:2023-11-03 19:41:58 24 4
gpt4 key购买 nike

<body ng-app="">
{% extends "pmmvyapp/base.html" %}
{% load crispy_forms_tags %}
{% load static %}
{% block content%}
<div class="col-md-8">
<form method="post" action="/personal_detail/">
{% csrf_token %}
<div class="form-group">
<div class=" mb-4">
<h6><u>Please Fill up the details below (Note that required field are marked by '*' )</u></h6>
</div>
<legend class="border-bottom mb-4" ,align="center">1.Beneficiary Details</legend>
<label for="formGropuNameInput">Does Beneficiary have an Adhaar Card?*</label>
<input type="radio" name="showHideExample" ng-model="showHideTest" value="true">Yes
<input type="radio" name="showHideExample" ng-model="showHideTest" value="false">No
<!--logic for yes-->
<div ng-show="showHideTest=='true'">
<div class="form-group">
<label for="formGropuNameInput">Name of Beneficiary(as in Aadhar Card)*</label>
<input name="bname" class="form-control" id="formGroupNameInput" placeholder="Enter name of Beneficiary as in Aadhar Card" required>
</div>


<div class="form-group">
<label for="phone">Aadhaar Number(Enclose copy of Aadhaar Card)*:</label>
<input name="aadharno" class="form-control" id="aadhar" name="aadhar"
pattern="^\d{4}\s\d{4}\s\d{4}$" placeholder="Enter Aadhar Card number with proper spacing"
required>
</div>
</div>
<!--logic for no-->
<div ng-show="showHideTest=='false'">

<div class="form-group">
<label for="formGroupDistrict">Please provide any of the following Identity Card*:</label>
<select name="idcard" id="formGroupDistrict" required>
<option>Bank or Post Office photo passbook</option>
<option>Voter ID Card</option>
<option>Ration Card</option>
<option>Kishan Photo Passbook</option>
<option>Passport</option>
<option>Driving License</option>
<option>PAN Card</option>
<option>MGNREGS Job Card</option>
<option>Her husband's Employee Photo Identity Card issued by the government
or any Public Sector Undertaking</option>
<option>Any other Photo Identity Card issued by State Government or Union Territory Administrations</option>
<option>Certificate of Identity with photograph issued by a Gazetted Officer on Official letterhead</option>
<option>Health Card issued by Primary Health Centre(PHC) or Government Hospital</option>
<option>Any other document specified by the State Government or Union Territory Adminstration</option>
</select>
</div>

<div class="form-group">
<label for="phone">Aadhaar Enrollment ID(EID):</label>

<input name="eid" class="form-control" id="aadhar" name="aadhar"
placeholder="Enter Aadhar Enrollment ID">
</div>


<div class="form-group">
<label for="formGropuNameInput">Name of Beneficiary(as in Identity Card)* </label>
<input name="bbname" class="form-control" id="formGroupNameInput" placeholder="Enter your name" required>
</div>


<div class="form-group">
<label for="idno">Identity Number(Enclose Copy of Identity Card)*:</label>

<input name="idno" id="identityno" class="form-control"
required>
</div>
</div>
</div>


<button type="submit" class="btn btn-primary" style="margin-bottom:10px ">Submit</button>
</form>
</div>
{% endblock %}
</body>

当我只填写"is"表单时,它不会提交,只有当我填写这两个表单时才会提交,我也会得到一个

MultiValueDictKeyError at /personal_detail/ 'adhaarno'

这是我的代码的views.py

views.py
def ApplyOnline(request):
return render(request,'users/applyonline.html')

def personal_detail(request):
bname=request.POST['bname']
adhaarno=request.POST['adhaarno']
# adhaarcopy =request.POST['adhaarcopy']

idcard=request.POST['idcard']
eid=request.POST['eid']
bbname=request.POST['bname']
idno=request.POST['idno']
# idcopy=request.POST['idcopy']
apply_online = Personal_Detail(bname=bname,adhaarno=adhaarno,
idcard=idcard,eid=eid,bbname=bbname,idno=idno)
apply_online.save()
return render(request,'users/applyonline.html')

我已经创建了模型,对于是的表单名称,我将名称指定为 bname,对于非表单名称,我将名称指定为 bbname模型.py

class Personal_Detail(models.Model):
bname=models.CharField(max_length=30)
adhaarno=models.IntegerField()
adhaarcopy = models.ImageField(upload_to='adhaar/')

idcard=models.TextField()
eid=models.IntegerField()
bbname=models.CharField(max_length=30)
idno=models.IntegerField()
idcopy=models.ImageField(upload_to='identitycard/')

def __str__(self):
return self.bname

我认为问题是由于复选框造成的,这就是我收到 MultiValueDictKeyError 的原因。另外我应该做什么,这样只有一个表单部分,例如我只填写了提交的"is"表单,但现在我需要同时填写这两个表单表格。

最佳答案

使用ng-if指令:

<!--logic for yes-->
̶<̶d̶i̶v̶ ̶n̶g̶-̶s̶h̶o̶w̶=̶"̶s̶h̶o̶w̶H̶i̶d̶e̶T̶e̶s̶t̶=̶=̶'̶t̶r̶u̶e̶'̶"̶>̶
<div ng-if="showHideTest=='true'">
<!-- ... -->
</div>
<!--logic for no-->
̶<̶d̶i̶v̶ ̶n̶g̶-̶s̶h̶o̶w̶=̶"̶s̶h̶o̶w̶H̶i̶d̶e̶T̶e̶s̶t̶=̶=̶'̶f̶a̶l̶s̶e̶'̶"̶>̶
<div ng-if="showHideTest=='false'">
<!-- ... -->
</div>

ng-if指令添加和删除 DOM。 ng-show指令仅通过 CSS 更改可见性。

<小时/>

更新

what about the MultiValueDictKeyError while submission?

ERRONEOUS

  <div class="form-group">
<label for="phone">Aadhaar Number(Enclose copy of Aadhaar Card)*:</label>
<input name="aadharno" class="form-control" id="aadhar" name="aadhar"
pattern="^\d{4}\s\d{4}\s\d{4}$" placeholder="Enter Aadhar Card number with proper spacing"
required>
</div>

<input>元素有两个name属性。

检查 HTML 中是否有其他重复的属性。

关于javascript - 未提交单个复选框表单。提交时还会收到 MultiValueDictKeyError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60371247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com