我知道如何通过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"/>