【发布时间】:2014-03-08 02:35:37
【问题描述】:
我知道如何通过 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"/>
【问题讨论】:
标签: python django file-upload upload uploading