Hi Iaspal,

here is what I think:
 - Why do you use try:...except? You don't see the real traceback.
   If you want to add debugging information (eg. logging.error('...'))
you could do it like this:
try:

except:
    logging.error('...')
    raise # reraise exception

 - Why do you use HttpResponse for the canvas? You could use cStringIO or
  a tempfile.

 - Please post the traceback, if you ask for help. It shows where the 
root of the problem is.

  Thomas

laspal schrieb:
> Hi,
> I am trying to generate pdf file and send the generated file by mail
> to the user.
> But I am getting value error as I am not sure how to attach file.
>
> here is my view function:
>
> def companies_report(request, companyid):
>     _user = request.user
>     sender = _user.email
>     company = Company.objects.get(id= companyid)
>     response = HttpResponse(mimetype='application/pdf')
>     response['Content-Disposition'] = 'attachment;
> filename=report1.pdf'
>
>     p = canvas.Canvas(response)
>     p.drawString(100, 100, "Hello world.")
>
>     p.showPage()
>     p.save()
>     try:
>         subject = "Company Report"
>         message = "Company report"
>         send_to = _user.email
>         attach = response
>         mail = EmailMessage(subject, message, sender,[send_to])
>         mail.attach(attach.name, attach.read(), attach.content_type)
>         mail.send()
>     except Exception, e:
>         raise ValueError, e
>     request.user.message_set.create(message="Mail sent successfully.")
>     return HttpResponseRedirect('../')
>
> The problem here is if I say attach = response then I am getting error
> 'HttpResponse' object has no attribute 'name'
> So my question is how to attach the generated file in EmailMessage.
>
> Thanks.
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to