Hi Malcolm! Actually I tried the following (and gave Ned credit for solving half of my problem):
from django.http import HttpResponse from django.shortcuts import render_to_response import urllib def front(request): sock = urllib.urlopen("/home2/a12007/webapps/officeprofiler/profiler/templates/officechoice.html") html = sock.read() sock.close() return HttpResponse(html) def officereport(request): selected_choice = request.POST['office'] sock = urllib.urlopen("/home2/a12007/webapps/officeprofiler/profiler/"+selected_choice) html = sock.read() sock.close() # response = HttpResponse(pdfbytes, mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename='+selected_choice return response When I comment out the attachment statement, so the pdf is to be viewed, it doesn't work. However, when I comment out the non-attachment version, I get the download box. That is why previously I said that it solved half of my problem. That is the case at WebFaction hosting. When I am at work on a Linux server there it tells me that "pdfbytes" is undefined. So I am not sure what to do at this stage. Sorry for any confusion. Cheers! -Warren ----- Original Message ----- From: "Malcolm Tredinnick" <[EMAIL PROTECTED]> To: <django-users@googlegroups.com> Sent: Wednesday, April 04, 2007 6:13 PM Subject: Re: Django app serves PDFs but browser doesn't render them > > On Wed, 2007-04-04 at 17:31 -0700, queezy wrote: >> Hi! >> >> Sorry it took a while - I had to get the info from work. >> >> Renderer mode: Quirks mode >> Cache source: Not cached >> Encoding: UTF-8 >> >> The other stuff was blank. >> >> My view is as follows: >> >> ========== SNIP ========== >> from django.http import HttpResponse >> from django.shortcuts import render_to_response >> import urllib >> >> def front(request): >> sock = >> urllib.urlopen("/home2/a12007/webapps/officeprofiler/profiler/templates/officechoice.html") >> html = sock.read() >> sock.close() >> return HttpResponse(html) >> >> def officereport(request): >> selected_choice = request.POST['office'] >> sock = >> urllib.urlopen("/home2/a12007/webapps/officeprofiler/profiler/"+selected_choice) >> html = sock.read() >> sock.close() >> return HttpResponse(html) > > If this is the method that returns your PDF, the problem is clear. You > are NOT setting the mimetype. So Django defaults to sending it with an > HTML mimetype and your browser correctly respects that and tries to > display the result as if it were an HTML. You have to set the mimetype > for any non-HTML data. This was mentioned earlier in the thread -- Ned > even gave you an example. > > Regards, > Malcolm > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---