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.

VIEW.PY


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


    

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2a6ef8f4-5153-4845-87dc-0fbe92e66469%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to