Make Django return response as a “different filename”

后端 未结 1 1150
自闭症患者
自闭症患者 2021-02-13 02:08

I have a Django view which returns an HttpResponse with a special MIME type to make the user\'s browser \"download\" the file instead of view it in the browser. Th

1条回答
  •  再見小時候
    2021-02-13 02:40

    There's a relevant example in the docs:

    from django.http import HttpResponse
    
    def some_view(request):
        # Create the HttpResponse object with the appropriate headers.
        response = HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
        return response
    

    0 讨论(0)
提交回复
热议问题