I have below code for upload file but i need to implement drag and drop functionality on top of that in django please help with my code.
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')
All you need to do is add class="dropzone" to your form. See this answer for details: https://stackoverflow.com/a/54654196/2606766
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With