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'
非常感謝你的工作 –