2016-06-27 1 views
1

서버에 여러 파일 필드를 저장하려고합니다. 필드 입력란은 동적이며 추가 버튼을 사용하여 원하는만큼 파일을 업로드 할 수 있습니다. 폼 전송이나 드롭 존을 사용하고 싶지 않습니다. 아무도 나를 어떻게 도와 줄 수 있습니다.jquery와 Ajax를 사용하여 django에 여러 파일 필드를 저장하는 방법

<div class="row" id="point_of_interest"> 
     <div class="col-lg-4 ">    
      <label>Point of Interest Name</label> 
      <input type="text" name="point_of_interest_name" class="form-control interest_name" > 
      <label class="error" style="color:red; display:none;"></label> 
     </div> 
     <div class="col-lg-4 ">    
      <label>Upload Image</label> 
      <input type="file" accept="image/*" name="point_of_interest_image[]" class="poi_img form-control" placeholder="Upload image" > 
     </div> 
     <div class="col-lg-4 ">    
      <div class="form-group"> 
       <a class="fa fa-plus-circle fa-lg add_point_of_interest" style="margin-top:33px;" ></a> 
      </div> 
     </div> 
    </div> 

위의 HTML은 위의 jQuery 코드는 내가 모든 파일

의 목록을 얻고있다 위의 코드를 사용하여 여러 개체

@csrf_exempt 
    def save_city_data(request): 
    try: 
     print '=====request========',request.POST 
     print  '=====request========',request.FILES.getlist('point_of_interest_image_list') 

를 수집하기 위해 동적으로 추가 양식 필드

$('#point_of_interest').find('input[type=file]').each(function (index,val) { 

     var city_image = $(this).prop(files)[0]; 
    console.log(city_image); 
    point_of_interest_image_list.push(city_image); 

    }); 

입니다

답변

0

Jquery 파일 업로드 플러그인

를 사용할 수 있습니다.
관련 문제