2010-04-25 1 views
0
def upload_file(request, step_id): 
    def handle_uploaded_file (file): 
     current_step = Step.objects.get(pk=step_id) 
     current_project = Project.objects.get(pk=current_step.project.pk) 

     path = "%s/upload/file/%s/%s" % (settings.MEDIA_ROOT, current_project.project_no, current_step.name) 
     if not os.path.exists (path): 
      os.makedirs(path) 
     fd = open(path) 
     for chunk in file.chunks(): 
      fd.write(chunk) 
     fd.close() 

    if request.method == 'POST': 
     form = UploadFileForm(request.POST, request.FILES) 
     if form.is_valid(): 
      handle_uploaded_file(request.FILES['file']) 
      return HttpResponseRedirect('/success/url/') 
    else: 
     form = UploadFileForm() 
    return render_to_response('projects/upload_file.html', { 
                 'step_id': step_id, 
                 'form': form, 
                 }) 

답변

2

path에 필요한 권한이 있는지 확인하십시오. 파이썬/django 프로세스를 실행하는 사용자는 write 권한이 있어야합니다. chmod0777의 경로 - 프로덕션에는 적합하지 않지만 파일 시스템 권한이 문제의 근원인지 신속하게 확인합니다.

+0

감사합니다. 어떻게 경로를 chmod 할 수 있습니까? – Semanty

+0

쉘 액세스 권한이 있다고 가정하면'chmod -R 0777 path/to/uploads'를 실행하십시오. – Matt

+0

죄송합니다. chmod와 chmod를 실행하는 셸을 사용하는 방법에 대해서는별로 몰라요. – Semanty

관련 문제