2014-02-10 68 views
2

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

回答

-2

你可以使用Django過濾器

rerfer:https://github.com/stefanfoulis/django-filer

+0

非常感謝。但是,請你解釋一下我怎樣才能在我的情況下正確應用過濾器?謝謝。 – Tengerye

+0

Django過濾器不能這樣做。我的結論是Django不能做到這一點呢。 – Tengerye

+0

與問題無關 –