django output pdf problem

45 views
Skip to first unread message

张永强

unread,
Apr 23, 2014, 11:31:44 PM4/23/14
to django...@googlegroups.com
In my program, I want to generate a pdf and output to the browser.

the server end code is:

response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="' + orderNumber + '.pdf"'
response.write(pdf)
return response

In the code, the type of pdf is 'str'

the ajax code is:

$.ajax({
    type:'POST',
    url:'/orderplace/',
    data:{provider:provider, providerId:providerId, orderNumber:orderNumber},
    success:function(resultData) {
          ;
    }
});

when i click the relevent button, the network condition is:

but i don't get the browser's “Save as...” dialogue as the django document said.

the next time, I use the original code snippet in the document as the views of /orderplace/ request, but still can't get the "Save as..." dialogue

where the problem is ??


Tom Evans

unread,
Apr 24, 2014, 7:56:12 AM4/24/14
to django...@googlegroups.com
On Thu, Apr 24, 2014 at 4:31 AM, 张永强 <shou...@gmail.com> wrote:
>
> In my program, I want to generate a pdf and output to the browser.
>
> the server end code is:
>
> response = HttpResponse(content_type='application/pdf')
> response['Content-Disposition'] = 'attachment; filename="' + orderNumber + '.pdf"'
> response.write(pdf)
> return response
>
> In the code, the type of pdf is 'str'
>
> the ajax code is:
>
> $.ajax({
> type:'POST',
> url:'/orderplace/',
> data:{provider:provider, providerId:providerId, orderNumber:orderNumber},
> success:function(resultData) {
> ;
> }
> });

You cannot download files with AJAX. Make a regular request.

Cheers

Tom

Andre Terra

unread,
Apr 24, 2014, 9:44:02 AM4/24/14
to Django users
Relevant Stack Overflow question/answer: http://stackoverflow.com/a/9970672/447485

In short, you can't do it over simple Ajax, but you can emulate it.


Cheers,
AT



--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1JES94hqHGNkcacE65s_qAuJ6nK%3Db7gT6RaynmxeFopng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages