标签:django
from django import forms class ContactForm(forms.Form): subject = forms.CharField() email = forms.EmailField(required=False) message = forms.CharField()
from django.shortcuts import render_to_response from mysite.contact.forms import ContactForm def contact(request): if request.method == ‘POST‘: form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd[‘subject‘], cd[‘message‘], cd.get(‘email‘, ‘noreply@example.com‘), [‘siteowner@example.com‘], ) return HttpResponseRedirect(‘/contact/thanks/‘) else: form = ContactForm() #必须加最后一句否则或出错return render_to_response(‘contact/contact_form.html‘, {‘form‘: form},context_instance=RequestContext(request))
contact_form.html
<html> <head> <title>Contact us</title> </head> <body> <h1>Contact us</h1> {% if form.errors %} <p style="color: red;"> Please correct the error{{ form.errors|pluralize }} below. </p> {% endif %} <form action="" method="post"> {% csrf_token %} <table> {{ form.as_table }} </table> <input type="submit" value="Submit"> </form> </body> </html>更多关于 android开发 的文章
标签:django
原文地址:http://blog.csdn.net/androidmylove/article/details/41774935