Hallo, I want to do a view to retur me a PDF with my models tah I have in models.py , I habe python 3 Django 2.11 and the models are in POSTGRESQL .
The next is my code that a I have, but gived TypeError: pruebapdf() missing 1 required positional argument: 'DesdeJango'
'DesdeJango'= is model name.
def pruebapdf(request,DesdeJango):
response=HttpResponse(content_type='application/pdf')
response['Content-Disposition']='attachment; filename=PDF_CON _MODELO.pdf'
buffer=BytesIO()
c=canvas.Canvas(response,pagesize=A4)
#Estilo
styles = getSampleStyleSheet()
styleBH=styles["Normal"]
styleBH.alignment = TA_CENTER
styleBH.fontSize=10
#parametros
folio=Paragraph('folio',styleBH)
nombre=Paragraph('nombre',styleBH)
sexo=Paragraph('sexo',styleBH)
edad=Paragraph('edad',styleBH)
gecha=Paragraph('gecha',styleBH)
formato=[]
formato.append(['folio','nombre','sexo','edad','gecha'])
#Estilo de la tabla
styleN=styles['BodyText']
styleN.alignment=TA_CENTER
styleN.fontSize=7
#ALTURA
high=650
#ModeloPrueba(request.POST,instance=mascota)
#ciclo for para poner la base de datos
for dato in DesdeJango.objects.all():
dato=[dato['folio'], dato['nombre'],dato['sexo'],dato['edad'],dato['gecha']]
formato.append(dato)
#ponemos el grosor del la fila
high=high-18
#AÑADIMOS DATOS DE PAGINACION
width, height=A4
table=Table(formato,colWidths=[1.9*cm,9.5*cm,1.9*cm,1.9*cm,1.9*cm])
table.setStyle(TableStyle([('INNERGRID',(0,0),(-1,-1),0.25, colors.black), ]))
table.wrapOn(c, width, height)
table.drawOn(c,30,high)
c.showPage()
c.save()
pdf=buffer.getvalue()
c.showPage()
c.save()
pdf = buffer.getvalue()
buffer.close()
response.write(pdf)
return response
URL.PY
path(r'html',pruebapdf , name='PDF'),
NOTE : AttributeError: 'WSGIRequest' object has no attribute 'objects'
I thank you in advance for your support