如何使用基于函数的视图获取重定向URL?

时间:2019-11-07 18:44:39

标签: python django django-views

我有2个视图,display_quotequoteline_update

更新quoteline之后,我要重定向到display_quote(更新的quoteline所属的引用)。 我收到错误:

Reverse for 'display_quote' with no arguments not found. 1 pattern(s) tried: ['\\^display_quote/\\(\\?P(?P<pk>[^/]+)\\\\d\\+\\)\\$$']
Exception Type:NoReverseMatch

观看次数:

def display_quote(request, pk):
    items_quote = Quote.objects.filter(pk=pk)
    items_quote_line = LineQuote.objects.all().filter(num_quote_id=pk)

    form = QuoteLineForm(request.POST or None)
       if request.method == "POST":
        if form.is_valid():
            form.save()
    total = 0
    for item in items_quote_line:
        total = total + item.get_price()

    context = {'items_quote': items_quote,
               'items_quote_line': items_quote_line,
               'form': form,
               'total':total
              }

    return render(request, 'quote/quote_display.html', context)


    def quoteline_update(request, pk):
    model = QuoteLine
    cls = LigneDevisForm
    item = get_object_or_404(model, id=pk)

    if request.method == "POST":
        form = cls(request.POST, instance=item)
        if form.is_valid():
            form.save()
            return redirect('display_quote')
    else:
        form = cls(instance=item)

        return render(request, 'quote/quoteline_update.html', {'form': form})

0 个答案:

没有答案