【发布时间】:2019-03-20 12:09:23
【问题描述】:
我有def,它通过对 django-admin 的操作呈现为 pdf。
def Print(self, request, obj):
data = {
'obj':obj
}
pdf = render_to_pdf('daa/imprimir/pdf.html', data)
if pdf :
response = HttpResponse(pdf, content_type='application/pdf')
filename ="Avaria_%s.pdf" %("123451231")
content = "inline; filename='%s'" %(filename)
response['Content-Disposition'] = content
download = request.GET.get("download")
if download:
content = "attachment; filename='%s'" %(filename)
response['Content-Disposition'] = content
return response
return HttpResponse("Not found")
关于我的行为,我有:
class ModelAdmin(admin.ModelAdmin):
actions = [Print]
而且一切正常,我选择了我想要渲染的对象,在我的html 中,我有一个 cicle,列出了我想要的那些 obj 的所有字段。
但现在我不想将列表呈现为 pdf。我只想渲染 1 个 obj。所以我创建了一个自定义按钮来做到这一点。
所以当我点击按钮时,我想将打开的 obj 渲染为 pdf。我不知道我需要做什么来获取我的定义,但在按钮内部
【问题讨论】:
标签: django pdf django-admin rendering