2
大家好,因为我在Django的学习阶段,所以支持我。 我必须在django中生成pdf报告。我希望细节应该从数据库中挑选出来并显示在pdf文档中。我正在使用报告实验室。 现在看看代码django输出pdf
def pdf_view(request):
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=hello.pdf'
p = canvas.Canvas(response)
details = Data.objects.all()
print details
p.drawString(20, 800, details)
p.drawString(30, 700, "I am a Python Django Professional.")
p.showPage()
p.save()
return response
现在
为学习的榜样我已经在模型
class Data(models.Model):
first_name = models.CharField(max_length =100,blank=True,null=True)
last_name = models.CharField(max_length =100,blank=True,null=True)
def __unicode__(self):
return self.first_name
做了两个领域,我想,在PDF文档中应该显示名S不管我通过填写管理员,但它给我的错误
'Data' object has no attribute 'decode'
Request Method: GET
Request URL: http://localhost:8000/view_pdf/
Django Version: 1.3
Exception Type: AttributeError
Exception Value:
我想PIK PDF文档中从数据库和显示细节
'Data' object has no attribute 'decode'
非常感谢你的工作 –