django文件上传,文件选择窗口不断弹出

时间:2018-09-07 10:15:07

标签: jquery django file-upload

我正在使用给定here的文件上传。在首次加载页面时,上传工作正常(上传字段为modal)。如果我再试一次,文件选择窗口将继续以提交/取消/关闭模式弹出,并且上传似乎无效。我找不到问题所在。请帮助。

修改
我已将默认上传(链接中的一个)按钮替换为自定义按钮。 Link

views.py

class BasicUploadView(View):
    def get(self, request):
        return render(self.request, 'contacts/up.html')

    def post(self, request):
        form = PhotoForm(self.request.POST, self.request.FILES)
        if form.is_valid():
            photo = form.save()
            data = {'is_valid': True, 'name': photo.file.name, 'url': photo.file.url}
        else:
            data = {'is_valid': False}
        return JsonResponse(data)

def finalUpload(request,id):
    form=add_document_form(request.POST)
    if form.is_valid():
        title=form.cleaned_data['title']
        document=form.cleaned_data['document']
        doc_related_to=form.cleaned_data['doc_related_to']
        doc_related_deals=form.cleaned_data['doc_related_deals']
        doc=documents(title=title,related_to=doc_related_to,rlated_deals=doc_related_deals,document=document)
        doc.save()
        obj = documents.objects.latest('id')
        for contact_id in obj.related_to:
            activityUpdate("document",obj.id,"1",contact_id,form.cleaned_data['title'],"0")
        Photo.objects.all().delete()
        return HttpResponse("done") 
    return HttpResponse(form)

0 个答案:

没有答案