gpt4 book ai didi

django - 如何在django中实现拖放上传文件,而我已经实现了简单的文件上传

转载 作者:行者123 更新时间:2023-12-05 05:13:14 25 4
gpt4 key购买 nike

我有以下上传文件的代码,但我需要在 django 中实现拖放功能,请帮助我的代码。

上传.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')

最佳答案

您需要做的就是将 class="dropzone" 添加到您的表单中。有关详细信息,请参阅此答案: https://stackoverflow.com/a/54654196/2606766

关于django - 如何在django中实现拖放上传文件,而我已经实现了简单的文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53812611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com