在django中获取隐藏字段值中的错误

时间:2013-05-29 10:10:11

标签: jquery django

的index.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>

models.py

class userdetails(models.Model):
     emailid=models.CharField(max_length=500)

forms.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]

views.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})  

我在段落标记中收到错误消息,但我无法在隐藏字段中收到错误消息。它变得不确定。这有什么不对吗?任何人都可以帮忙吗?请!

0 个答案:

没有答案