我有以下代码用于上传文件,但我需要在Django的基础上实现拖放功能,请帮助我的代码。
upload.html
{% block content %}
<div method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile"><br><br>
<input type="submit" value="upload">
{% endblock %}
Views.py
def simple_upload(request):
# return HttpResponse("<H2>Upload</H2>")
if request.method == 'POST' and request.FILES['myfile']:
myfile = request.FILES['myfile']
fs = FileSystemStorage(location="ciscotest/uploadedmedia")
filename = fs.save(myfile.name, myfile)
uploaded_file_url = fs.url(filename)
return render(request, 'upload.html', {'uploaded_file_url': uploaded_file_url,"fileupload":"File uploaded successfully"})
return render(request, 'upload.html')
答案 0 :(得分:0)
您需要做的就是将 class =“ dropzone” 添加到表单中。有关详细信息,请参见以下答案: https://stackoverflow.com/a/54654196/2606766