我是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。有人能在这里帮我吗?
提前感谢!
发布于 2017-05-04 05:25:51
您希望在页面上显示什么内容?你不需要一个基于类的视图来做到这一点(但是你可以使用它)。你可以简单地写下:
def my_view(request):
send_mail(paramters here)
# Add whatever object you think you'd need on the page in the context (the
# third paramter of render {}.
# render adds request to response so it's preferred. render_to_response may be deprecated soon. If it has not been already
return render(request, 'loanwolf/customers/request.html', {})https://stackoverflow.com/questions/43770057
复制相似问题