反向找不到

时间:2019-05-04 17:49:41

标签: python django

我对重定向有一些疑问。当我使用mapviews.index时没有错误,但是当我使用mpviews.index

Reverse for 'mythicPlus.views.index' not found. 'mythicPlus.views.index' is not a valid view function or pattern name

我该怎么做才能解决此问题?

shopping_cart / views.py

from mythicPlus import views as mpviews
from mainPage import views as mapviews

return redirect(reverse(mpviews.index))

mythicPlus / urls.py

path('', views.index, name = 'mythicPlus_list'),

mythicPlus / views.py

def index(request):
    boost_keys_list = mythicPlusOrders.objects.all()
    context = {'object_list': boost_keys_list}
    return render(request, "mythicPlus/posts.html", context)

mainPage / views.py

def index(request):
    return render(request, 'mainPage/homePage.html')

1 个答案:

答案 0 :(得分:0)

reverse使用网址中的视图名称,因此在path('my-url/', views.MyView.as_view(), name="my-view")中,视图名称为“我的视图”

您需要在reverse中提供它。或者你可以做 redirect(mpviews.index)