How to return static files passing through a view in django?

前端 未结 8 1828
名媛妹妹
名媛妹妹 2020-12-09 09:04

I need to return css files and js files according to specific logic. Clearly, static serve does not perform what I need. I have a view, whose render method uses logic to fin

8条回答
  •  半阙折子戏
    2020-12-09 09:57

    This is what I used:

    test_file = open('/home/poop/serve/test.pdf', 'rb')
    response = HttpResponse(content=test_file)
    response['Content-Type'] = 'application/pdf'
    response['Content-Disposition'] = 'attachment; filename="%s.pdf"' \
                                      % 'whatever'
    return response
    

提交回复
热议问题