嗨,我有一个模型表单,它是根据找到的文档完成的: https ://docs.djangoproject.com/en/dev/topics/forms/modelforms/
我的反馈表的一些属性:
模型.py
class Feedback(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
title = models.CharField(max_length=200)
feedback = models.TextField()
类FeedbackForms(ModelForm):类元:模型=反馈
forms_details.py
def save_form(request):
if request.method == 'POST':
form = FeedbackForms(request.POST)
if form.is_valid():
form.save()
name = form.cleaned_data['name']
email = form.cleaned_data['email']
title = form.cleaned_data['title']
feedback = form.cleaned_data['feedback']
email = EmailMessage("%s" % title, "%s <%s> said: %s" % (name, email,feedback),
to=['smth@example.com'])
email.send()
return render_to_response("success.html")
else:
form = FeedbackForms()
return render_to_response("form.html", {'form': form}, context_instance=RequestContext(request))
但是,现在我想在执行 POST 之前使用 jQuery 检查键入的电子邮件是否有效。
我在这里找到了类似于我需要的东西,但它是用于表单的。我已经尝试过了,但它不适用于我的 ModelForm。