upload.html
viewsTitle
from django.views.decorators.csrf import csrf_exempt @csrf_exempt def upload(request): if request.method == "POST": file_obj = request.FILES.get("up_file") with open(file_obj.name, "wb") as f: for line in file_obj: f.write(line) return HttpResponse("ojbk") return render(request, "upload.html") 避免403报错,可以在前端加{% csrf_token %} 或者在后端引入@csrf_exempt,不过这个方法只是关闭了校验