索引.html
<html>
<head>
<title>index</title>
<script type="text/javascript">
$(document).ready(function(){
alert($("errormsg").attr("value"));
});
</script>
</head>
<body>
{% if form.emailid.errors %}
<input type="text" id="errormsg" value="{{ form.emailid.errors }}"/>
{% endif %}
{{ form.emailid }}
</body>
</html>
模型.py
class userdetails(models.Model):
emailid=models.CharField(max_length=500)
表格.py
class new_register(ModelForm):
emailid=forms.CharField(widget=forms.TextInput())
class Meta:
model=userdetails
def clean_emailid(self):
rcvd_mailid = self.cleaned_data.get('emailid')
if rcvd_mailid:
user_qs = userdetails.objects.filter(emailid = rcvd_mailid)
qs_count=user_qs.count()
if qs_count >= 1:
raise forms.ValidationError("* Mail Id Already Exists")
return self.cleaned_data['emailid'][:100]
视图.py
def register_view(request, template_name="index.html"):
if request.method=="POST":
user_values=new_register(data=request.POST)
if user_values.is_valid():
user_values.save()
return HttpResponseRedirect(reverse("url_indexpage"))
else:
return render(request, template_name,{'form':user_values})
elif request.method=="GET":
user_values=new_register()
return render(request, template_name,{'form':user_values})
我在段落标签中收到错误消息,但我无法在隐藏字段中获得错误消息。它变得不确定。这有什么不对吗?任何人都可以帮忙吗?请!