文档很仔细,但熟悉要慢慢来~~
from django.shortcuts import render from contact.forms import ContactForm from django.http import HttpResponseRedirect from django.core.mail import send_mail def 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})
时间: 2024-10-31 18:58:38