【问题标题】:Django Python 3.* : Reverse for 'view' not foundDjango Python 3.*:找不到“视图”的反向
【发布时间】: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'),

我也尝试过这些重定向语法:

  1. return redirect('first_view', id)
  2. return redirect('first_view', args=[id])
  3. return redirect('first_view', args=[id=id])
  4. return redirect(first_view(id=id))
  5. return redirect(first_view(id))
  6. return redirect(first_view(request=request,id=id))
  7. return redirect(first_view(request,id))

没有任何作用!任何支持将不胜感激。

【问题讨论】:

    标签: python-3.x django-views django-urls django-3.0 django-url-reverse


    【解决方案1】:

    这是节省您时间的问题..

    当您调用 redirect() 时,请确保您传递的是 url 名称 而不是 view def name

    【讨论】:

      猜你喜欢
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 2018-01-28
      • 2010-10-12
      • 2013-10-05
      • 2020-07-21
      相关资源
      最近更新 更多