I make a PDF based on data from the database. the error 'int' object has no attribute 'decode' occurs
view:
def spisok_pdf(request, title="Список покупок", aka=""): # генерация pdf ... sp = Model.objects.filter(user_spisok__username=me).order_by('-id')[0] response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename=try.pdf' c = canvas.Canvas(response) MyFontObject = ttfonts.TTFont('Arial', 'arial.ttf') pdfmetrics.registerFont(MyFontObject) c.setStrokeColor(brown) c.setFont('Times-Roman', 10) c.drawString(25, 820, "www.") c.setStrokeColor(gray) c.grid([0.3*inch, 5.4*inch, 6.4*inch, 7.4*inch], [#0.2*inch, 0.4*inch, 0.6*inch, 0.8*inch, 1*inch, 1.2*inch, 1.4*inch, 1.6*inch, 1.8*inch, 2*inch, 2.2*inch, 2.4*inch, 2.6*inch, 2.8*inch, 3*inch, 3.2*inch, 3.4*inch, 3.6*inch, 3.8*inch, 4*inch, 4.2*inch, 4.4*inch, 4.6*inch, 4.8*inch, 5*inch, 5.2*inch, 5.4*inch, 5.6*inch, 5.8*inch, 6*inch, 6.2*inch, 6.4*inch, 6.6*inch, 6.8*inch, 7*inch, 7.2*inch, 7.4*inch, 7.6*inch, 7.8*inch, 8*inch, 8.2*inch, 8.4*inch, 8.6*inch, 8.8*inch, 9*inch, 9.2*inch, 9.4*inch, 9.6*inch, 9.8*inch, 10*inch, 10.2*inch, 10.4*inch, 10.6*inch, 10.8*inch, 11*inch ]) c.setFont('Arial', 11) c.drawString(160, 780, "Наименование") c.setFont('Arial', 11) c.drawString(403, 780, "Кол-во") c.setFont('Arial', 11) c.drawString(480, 780, "Цена") # ДАННЫЕ c.setFont('Arial', 11) c.drawString(30, 765, sp.obj_1) c.setFont('Arial', 11) c.drawString(395, 765, sp.number_1) c.setFont('Arial', 11) c.drawString(466, 765, sp.price_1) # ИТОГ c.setFont('Arial', 14) c.drawString(403, 40, "Итог:") c.setFont('Arial', 14) c.drawString(473, 40, itog) c.showPage() c.save() return response
The model consists of CharField and InegerField. I can not understand why such a mistake can be? At what CharField displays correctly, and swears campaign on IntegerField. I can add data if required using Reportlab
Traceback: File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\handlers\base.py" in get_response 132. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Python34\nato4ka\shops\views.py" in spisok_pdf 100. c.drawString(395, 765, sp.number_1) File "C:\Python34\lib\site-packages\reportlab\pdfgen\canvas.py" in drawString 1503. text = text.decode('utf-8') Exception Type: AttributeError at /shops/spisok/print/ Exception Value: 'int' object has no attribute 'decode'