Skip to content Skip to sidebar Skip to footer

Download File From Django Project Root Using A Button

So, this is the webpage I'm creating atm with Django 1.8: Want the user to be able to export the data as .csv. When the user: writes a subreddit name in the box presses the butto

Solution 1:

You must first create the response object in order to assign headers to it.

defexport(request):
    filename = "test.csv"# this is the file people must downloadwithopen(filename, 'rb') as f:
        response = HttpResponse(f.read(), content_type='application/vnd.ms-excel')
        response['Content-Disposition'] = 'attachment; filename=' + filename
        response['Content-Type'] = 'application/vnd.ms-excel; charset=utf-16'return response

Taken from here

Post a Comment for "Download File From Django Project Root Using A Button"