views.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:django-monkeys 作者: andrew-gardner 项目源码 文件源码
def contactView(request):
    """
    A simple view that shows the Contact form and sends an e-mail to the
    administrators when submitted.
    """
    submitSuccess = False
    if request.method == 'GET':
        form = ContactForm()
    else:
        form = ContactForm(request.POST)
        if form.is_valid():
            fromEmail = form.cleaned_data['fromEmail']
            subject = form.cleaned_data['subject']
            message = form.cleaned_data['message']
            finalMessage  = "From user : " + str(request.user.username) + "\n"
            finalMessage += "Return e-mail : " + str(fromEmail) + "\n\n"
            finalMessage += ("-" * 30) + "\n\n"
            finalMessage += message

            # Send the mail
            try:
                send_mail(subject, finalMessage, fromEmail, settings.EMAIL_CONTACT_LIST)
            except BadHeaderError:
                return HttpResponse('Invalid e-mail header found.')
            submitSuccess = True

    context = {
                  'form' : form,
                  'submitSuccess' : submitSuccess
              }
    return render(request, 'contact.html', context)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号