导入模块
from django.http import HttpResponse, FileResponse
FileResponse模块实现文件的下载
views视图代码:
def download_template(request):
file = open('你的绝对路径', 'rb')
response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;文件的名字(1.txt)'
return response
urls代码:
path('download_template/', views.download_template)