【发布时间】:2020-04-13 10:35:15
【问题描述】:
我有一个 first_view 接受 id 参数,而 second_view 在解释一些代码后重定向到 first_view .
views.py:
def first_view(request, id):
#do something
return render(request, 'sometemplate.html')
def second_view(request, id):
#do something
return redirect('first_view', id=id)
当我尝试通过 second_view 时出现此错误:
未找到“first_view”的反向。
urls.py:
path('first_view/<int:pnr_id>/', views.first_view, name='first_view'),
path('second_view/<int:pnr_id>/', views.second_view, name='second_view'),
我也尝试过这些重定向语法:
return redirect('first_view', id)return redirect('first_view', args=[id])return redirect('first_view', args=[id=id])return redirect(first_view(id=id))return redirect(first_view(id))return redirect(first_view(request=request,id=id))return redirect(first_view(request,id))
没有任何作用!任何支持将不胜感激。
【问题讨论】:
标签: python-3.x django-views django-urls django-3.0 django-url-reverse