NoReverseMatch位于/ customer / 1 / list /

时间:2018-11-13 04:10:21

标签: django upload

我试图在表单中创建上传功能,但是当我单击“上传”按钮时,它会引发错误:/ customer / 1 / list /

上的NoReverseMatch

这是视图中的代码

def list(request,pk):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            form.cId = pk;
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('list'))
            # render(request, 'list.html', {'documents': documents, 'form': form})
    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return

此处是网址中的代码

url(r'^customer/(?P<pk>\d+)/list/$', Views.list, name='list'),

请帮助

1 个答案:

答案 0 :(得分:1)

请用return HttpResponseRedirect(reverse('list'))替换return HttpResponseRedirect(reverse('list', args=[pk]))。请检查here以了解如何使用反向。希望对您有帮助!