首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NoReverseMatch /customer/1/list/

NoReverseMatch /customer/1/list/
EN

Stack Overflow用户
提问于 2018-11-13 04:10:21
回答 1查看 163关注 0票数 0

我试图在表单中创建一个上载函数,但是当我单击“上传”按钮时,它会抛出错误: NoReverseMatch at /customer/1/list/

下面是视图中的代码

代码语言:javascript
复制
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中的代码

代码语言:javascript
复制
url(r'^customer/(?P<pk>\d+)/list/$', Views.list, name='list'),

请帮帮忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-13 04:24:57

请将return HttpResponseRedirect(reverse('list'))替换为return HttpResponseRedirect(reverse('list', args=[pk]))。请检查这里看看如何使用反向。希望能帮上忙!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53273676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档