2011-08-16 51 views
0

爲什麼形式無效空像場...陷入數據庫空記錄空的像場無效

@login_required 
def add_photo(request, gallery_id): 
gallery = get_object_or_404(Gallery, pk=gallery_id) 
PhotoFormSet = formset_factory(PhotoUploadForm, extra=1) 
formset = PhotoFormSet() 
if request.method == "POST": 
    formset = PhotoFormSet(request.POST, request.FILES) 
    if formset.is_valid(): 
     for form in formset: 
      if form.is_valid(): 
       data = form.save(commit=False) 
       data.galleries = gallery 
       data.save() 
return render_to_response("add_photo.html", {'formset': formset, 'album_id': gallery_id}, context_instance=RequestContext(request)) 

回答

0

是否設置爲需要在場上=假在表單中的文件嗎?

我們能否看到窗體定義?

+0

解決了這個問題 if form.cleaned_data.get(「image」)不是無: –