首页 > 代码库 > DJANTO之FORM

DJANTO之FORM

文档很仔细,但熟悉要慢慢来~~

from django.shortcuts import renderfrom contact.forms import ContactFormfrom django.http import HttpResponseRedirectfrom django.core.mail import send_maildef contactview(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@examlple.com),                [siteowner@example.com],                )            return HttpResponseRedirect(/contact/thanks/)    else:        form = ContactForm(            initial={subject:I love this site}            )    return render(request, contact_form.html, {form:form})                

DJANTO之FORM