Django使用redirect重定向报错NoReverseMatch,代码如下
#urls.py
from django.urls import path
from . import views
urlpatterns=[
path('hello_world/',views.hello_world,name='hello_world'),
path('a/',views.a,name='a'),
]
#views.py
from django.shortcuts import render
from django.shortcuts import redirect
# Create your views here.
def hello_world(request):
return render(request,'hello_world.html')
def a(request):
return redirect('a:hello_world',permanent=True) #使用redirect函数将URL从a/重定向到hello_world/
报错:
NoReverseMatch at /a/
'a' is not a registered namespace
如何处理?谢谢