NoReverseMatch по адресу / customer / 1 / list / - PullRequest
0 голосов
/ 13 ноября 2018

Я пытаюсь сделать функцию загрузки в форме, но когда я нажимаю кнопку загрузки, она выдает ошибку: NoReverseMatch в / customer / 1 / list /

Вот код в представлении

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

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

, пожалуйста, помогите

1 Ответ

0 голосов
/ 13 ноября 2018

Пожалуйста, замените return HttpResponseRedirect(reverse('list')) на return HttpResponseRedirect(reverse('list', args=[pk])).Пожалуйста, проверьте здесь , чтобы увидеть, как использовать реверс.Надеюсь, это поможет !!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...