【发布时间】:2017-05-03 21:09:02
【问题描述】:
我是 Django 的新用户。我想通过单击按钮发送电子邮件(用于传真)。所以我在视图CustomerRequestUpdateView 中创建了方法send_fax。我在这里有点困惑。此方法是否必须使用 POST 请求?如何将“send_fax”渲染到我的模板?我希望该方法可以直接在类中实现。
class CustomerRequestUpdateView(RequestUpdateView):
template_name = 'loanwolf/customers/request.html'
url_namespace = 'customers'
def send_fax(self):
subject = 'The contract of %s' % self.customer.email_user
contact_message = 'This is just a test for later on during this project'
from_email = settings.EMAIL_HOST_USER
to_email = [from_email, ]
send_mail(
subject,
contact_message,
from_email,
to_email,
fail_silently=False,
)
return #render(request, template_name, context) render_to_pdf()
我以为我可以使用render_to_response() 或只使用render(),但我的方法使用self,而不是request。有人可以在这里帮助我吗?
提前致谢!
【问题讨论】:
-
该方法不会执行任何操作,只会执行名为 http 请求之一的函数