Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django force download file

import os
from django.conf import settings
from django.http import HttpResponse, Http404

def download(request, path):
    file_path = os.path.join(settings.MEDIA_ROOT, path)
    if os.path.exists(file_path):
        with open(file_path, 'rb') as fh:
            response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
            response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
            return response
    raise Http404
Comment

PREVIOUS NEXT
Code Example
Python :: df.loc jupyter 
Python :: pytorch rolling window 
Python :: pandas corr get couple value 
Python :: remove punctuation and special charaacters nltk 
Python :: How can I use Apache Spark with notebook in Anaconda 
Python :: mechanize python #6 
Python :: width and precision thousand separetor python 
Python :: sklearn model persistence 
Python :: Saving a copy of rcParams settings. 
Python :: append to a list without intializing 
Python :: django database specify schema 
Python :: pandas meerge but keep certain columns 
Python :: get first element of each group 
Python :: # swap variables 
Python :: Redirect to same page after POST method using class based views 
Python :: Doubleclick .py Prep 
Python :: python regex type hint 
Python :: allowed_hosts error ecs django 
Python :: how to find factorial number in python 
Python :: matplotlib insert small subplot into subplot 
Python :: python finding mead 
Python :: stop level of the broker 
Python :: godot get the closer node from array 
Python :: automate ms word with python 
Python :: pandas iloc stack overflow 
Python :: Python NumPy ravel function example array.ravel is equivalent to reshape(-1, order=order) 
Python :: differences between Pool.apply, Pool.apply_async, Pool.map and Pool.map_async. 
Python :: Python NumPy row_stack Function Example with 2d array 
Python :: como saber si un string es un numero python 
Python :: python cos not the same as calculator 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =