django:在传递所需变量后重定向回多模式视图

django:在传递所需变量后重定向回多模式视图,django,redirect,Django,Redirect,我收到错误信息: 找不到参数为“{laftion\u id':'21”,“sample\u id':'28780488}”的“botanyoverview”的反面。尝试了1种模式:[“植物学/植物学概览/浮动/?P[0-9]+/sample/?P[0-9]+$”] 这两个ID都存在,通常这是URL.py中的一个问题,但我似乎无法发现它 我有几个表/模型,它们显示在一个html视图中,单击其中一个,然后转到编辑页面,我试图修复重定向,使其返回到开始的概览页面,这需要浮动和示例ID。url最初工作,

我收到错误信息:

找不到参数为“{laftion\u id':'21”,“sample\u id':'28780488}”的“botanyoverview”的反面。尝试了1种模式:[“植物学/植物学概览/浮动/?P[0-9]+/sample/?P[0-9]+$”]

这两个ID都存在,通常这是URL.py中的一个问题,但我似乎无法发现它

我有几个表/模型,它们显示在一个html视图中,单击其中一个,然后转到编辑页面,我试图修复重定向,使其返回到开始的概览页面,这需要浮动和示例ID。url最初工作,但在编辑后尝试重定向回原始页面时抛出此错误。我看不出错误,有什么想法吗

views.py

def editplantpart(request, pk, fk='', sp='', fl=''):
        post = get_object_or_404(PlantPart, pk=pk)
        if request.method == "POST":
            form = PlantPartForm(request.POST, instance=post)
            if form.is_valid():
                post = form.save(commit=False)
                sample_id=sp
                flotation_id=fl
                post.save()
                return redirect('botanyoverview', {  'flotation_id': flotation_id, 'sample_id':sample_id,})

        else:
            form = PlantPartForm(instance=post)
        return render(request, 'plantpart/create_plantpart.html', {'form': form})
url.py

re_path('flotation/(?P<fl>\d+)/sample/(?P<sp>\d+)/fraction/(?P<fk>\d+)/plantpart/edit/(?P<pk>\d+)/edit/', views.editplantpart, name='editplantpart'),
html

@@@编辑

植物学概述网址

path('botanyoverview/flotation/<int:flotation_id>/sample/<int:sample_id>', views.botanyoverview, name='botanyoverview'),
您应该通过在案例参数中传递视图的名称和一些位置或关键字来调用重定向;URL将使用反向方法进行反向解析:

以下是一些重定向示例:


显示添加到上面的botanyoverview.url的url
path('botanyoverview/flotation/<int:flotation_id>/sample/<int:sample_id>', views.botanyoverview, name='botanyoverview'),
redirect('botanyoverview', flotation_id=flotation_id, sample_id=sample_id)