Tuesday, May 29, 2018

Re: Good afternoon, I need help to generate a PDF of my models in DJANGO

"pruebapdf() missing 1 required positional argument: 'DesdeJango'"

Your view have an additional parameter, which is not used by views; views always receive the "request" and then the list of parameters in your URL definition (which does not have any parameters). So you need to remove it from the function and actually import the class from your models.

On Tue, May 29, 2018 at 4:49 PM, ALDO JAVIER VIGUERAS <aldojvigueras@gmail.com> wrote:
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CAEM7gE3aSpne3G8Uzekj7v1KmhuOzUutF6w%2B9JFkbHd_gyRxwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment