views.py 文件源码

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

项目:Django-Web-Development-with-Python 作者: PacktPublishing 项目源码 文件源码
def download_cv_pdf(request, cv_id):
    cv = get_object_or_404(CV, pk=cv_id)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = "attachment; filename=%s_%s.pdf" % (cv.first_name, cv.last_name)

    html = render_to_string("cv/cv_pdf.html", {
        "cv": cv,
        "MEDIA_ROOT": settings.MEDIA_ROOT,
        "STATIC_ROOT": settings.STATIC_ROOT,
    })

    pdf = pisa.pisaDocument(
        StringIO(html.encode("UTF-8")),
        response,
        encoding="UTF-8",
    )

    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号