为啥未声明或定义变量,亦可以使用该变量?
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from contact.forms import ContactForms
def contact(request):
if request.method == 'POST':
form = ContactForms(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 = ContactForms(initial={'subject': 'I love your site!'})
return render_to_response('contact_form.html', {'form': form})