前端界面 templates
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div><h3 style="text-align: center">下载模板</h3></div>
<form method="post" enctype="multipart/form-data" action="{% url 'download' %}"
class="table table-bordered form-horizontal">
{% csrf_token %}
<input type="file" name="xsfile"/>
<input type="submit" value="提交"/>
</form>
</div>
</div>
</div>urls.py
url(r'^download/',download,name='download'),
views.py
from django.http import JsonResponse, FileResponsedef download(request):
'''
download下载模板
:param request:
:return:
'''
the_file_name = 'down.xlsx'
filename = 'download/down.xlsx'
file = open(filename, 'rb')
response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name)
return response结果:


本文展示了一个简单的前端界面用于文件上传,并通过 Django 实现了文件下载功能。具体包括 HTML 表单元素、POST 请求、文件响应等关键技术点。
1890

被折叠的 条评论
为什么被折叠?



