Django3.1.4从前端接收文件
博主有一个接口需求是要从前端接收zip文件,输入在后端的数据预处理函数中,其实用接收file的方式接收即可。
views.py文件
import os
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
from upload_file import settings
def form(request):
return render(request, 'upload_form.html')
def zipFile(request):
if request.method == 'POST':
zipFile = request.FILES['zipFile']
zipFile = os.path.join(settings.MEDIA_ROOT, zipFile.name)