iframe文件上传
views.py
def iframe(request):
if request.method == "GET":
return render(request, "iframe.html")
elif request.method == "POST":
post_file = request.FILES.get("post_file")
username = request.POST.get('username')
file_root = os.path.join('static/upload/', post_file.name)
with open(file_root, 'wb') as new_file:
for item in post_file.chunks():
new_file.write(item)
return HttpResponse(json.dumps("OK"))
iframe.html
<form action="{% url 'iframe' %}" method="post" target="ifm" enctype="multipart/form-data">
<iframe id="ifm" style="display: none"></iframe>
<input type="text" name="username" placeholder="username">
<input type="file" name="post_file">
<input type="submit" value="提交">
</form>