So i have try this:
file_da_scar = F_d.objects.get(pk=id)
    nom = file_da_scar.nome_fil
    return HttpResponse(open('/home/luca72/webapps/django/myproject/
disegni/'+nom+'.pdf', 'r').read(), mimetype='application/pdf')

And it open the pdf file, but if i need only to download without open
it how i
can proceed.

Thanks

Luca

On 22 Set, 09:02, luca72 <lucabe...@libero.it> wrote:
> Thanks I use cherry py because i don't know how to download file with
> django, can you tell me how to do it with django
>
> regards
>
> Luca
>
> On 14 Set, 12:46, "J. Cliff Dyer" <j...@sdf.lonestar.org> wrote:
>
> > On Mon, 2009-09-14 at 07:57 -0700, luca72 wrote:
> > > Hello i have try with cherrypy but i get this error:
>
> > > def scarico(request, id):
> > >     from cherrypy.lib.static import serve_file
> > >     fil_da_scar = F_d.objects.get(pk=id)
> > >     nome_file = fil_da_scar.nome_fil
> > >     return serve_file('/home/luca111/Desktop/Luca/Webframework/
> > > off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> > > 'attachment')
>
> > > Traceback (most recent call last):
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > basehttp.py", line 278, in run
> > >     self.result = application(self.environ, self.start_response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > basehttp.py", line 636, in __call__
> > >     return self.application(environ, start_response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/handlers/
> > > wsgi.py", line 245, in __call__
> > >     response = middleware_method(request, response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/middleware/
> > > common.py", line 83, in process_response
> > >     if response.status_code == 404:
>
> > > AttributeError: 'generator' object has no attribute 'status_code'
>
> > > What is wrong?
>
> > > Regards
>
> > > Luca
>
> > Well, assuming that scarico is getting called as "middleware_method
> > within the code, I'd have to say your problem is that cherrypy's
> > serve_file returns a generator object of some sort, rather than a django
> > HttpResponse object.  This is not surprising, as cherrypy has no reason
> > to interoperate properly with django.  What you need to do is either
> > catch the generator returned by serve_file, and adapt it to an
> > HttpResponse.  
>
> > Something like.
>
> > def cherrypy_to_HttpResponse(generator):
> >     #???
> >     return HttpResponse(*args, **kwargs)
>
> > def scarico(request, id):
> >     # same as before
> >     served_file = serve_file('/home/luca111/Desktop/Luca/Webframework/'
> >        + 'off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> >        'attachment')
> >     return cherrypy_to_HttpResponse(served_file)
>
> > Or figure out a way to do it directly in django.
>
> > I'm not sure exactly what you're trying to do, but if you just return
> > the content of the file with an appropriate Content-type set in your
> > response headers, I think it will work fine.
>
> > Cheers,
> > Cliff
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to