如何将表单数据作为上下文传递?

时间:2013-05-26 07:43:53

标签: django

我有这个PDFview类现在我想在任何表单模板中使用它,所以我可以在发送数据之前看到该表单数据的预览。

类PDFView(查看):

def get(self, request, **kwargs):
    template = get_template("pim/pdfview.html")
    ctx = {}
    ctx["test"] = Employee.objects.all()

    context = Context(ctx)
    html  = template.render(context)
    result = StringIO.StringIO()
    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
    if not pdf.err:
        response = http.HttpResponse(result.getvalue(), mimetype='application/pdf')
        response['Content-Disposition'] = 'attachment; filename="leavereport.pdf"'
        return response
    return http.HttpResponse('We had some errors<pre>%s</pre>' % cgi.escape(html)) 

0 个答案:

没有答案