我知道如何通过django上传多个文件,但是如果上传文件夹时存在子文件夹时出现问题。 Django无法接收子文件夹。我找到了原因,因为浏览器使用'。'代表一个文件夹,但Django无法解析它,然后停止解析。有没有一种优雅的方式来解决它?django如何上传文件夹
Python代码:
def uploader_single(request):
data = {}
if request.method == 'POST':
if True:
for afile in request.FILES.getlist('file'):
new_file = UploadFileSingle(file = afile)
new_file.save()
return HttpResponseRedirect('')
else:
print "form is not valid"
return HttpResponseRedirect('')
else:
print 'not post'
Python代码:
class UploadFileSingle(models.Model):
file = models.FileField(upload_to='files/%Y/%m/%d', models.FilePath)
uploaded_at = models.DateTimeField(auto_now_add=True)
models.FilePathField.recursive = True
models.FilePathField.allow_folders = True
updated_at = models.DateTimeField(auto_now=True)
def some_folder = FilePathField(path='some_path', recursive=True, allow_files=True, allow_folders=True,)'
HTML代码:
<input type="file" name="file" multiple = "true" webkitdirectory="true" directory = "true"/>
非常感谢。但是,请你解释一下我怎样才能在我的情况下正确应用过滤器?谢谢。 – Tengerye
Django过滤器不能这样做。我的结论是Django不能做到这一点呢。 – Tengerye
与问题无关 –