/blog/redirect2 处的 NoReverseMatch
NoReverseMatch at /blog/redirect2
我是 django 的新手,我一直在尝试测试 URL 重定向方法我已经尝试了两个选项,但是 return render() 一直给我这个没有反向匹配的错误
这是我的 urls.py 代码:
app_name = 'blog'
urlpatterns = [
# path('about', views.about, name = 'about'),
path('about.html', views.about, name='about'),
path('home.html', views.home, name='home'),
# path('home', views.home, name ="home")
path('redirect', views.redirect_view),
path('redirection_fct',views.redirection_fct, name='redir_fct'),
#redirection par la fonction as_view
path('redirect1', RedirectView.as_view(url='http://127.0.0.1:8000/blog/redirection_fct')),
path('redirect2', views.redirect_view1),
]
这是我的观点文件:
def about(request):
return render(request, 'about.html', {})
def home(request):
return render(request, 'home.html', {})
#redirection par HttpResponseRedirect
def redirect_view(request):
return HttpResponseRedirect("redirection_fct")
def redirect_view1(request):
return redirect('redir_fct')
def redirection_fct(request):
return render(request, 'redirection.html', {})
我的 URL 模式有问题还是渲染模式有问题?
这是您应用中的 urls.py
吗?你如何将它包含在你的项目中 urls.py
,如果你有一个命名空间,那么你可能需要这样的东西:
def redirect_view1(request):
return redirect('blog:redir_fct')
您可以尝试 运行 从 django shell:
from django.urls import get_resolver
print(get_resolver().reverse_dict.keys())
我是 django 的新手,我一直在尝试测试 URL 重定向方法我已经尝试了两个选项,但是 return render() 一直给我这个没有反向匹配的错误
这是我的 urls.py 代码:
app_name = 'blog'
urlpatterns = [
# path('about', views.about, name = 'about'),
path('about.html', views.about, name='about'),
path('home.html', views.home, name='home'),
# path('home', views.home, name ="home")
path('redirect', views.redirect_view),
path('redirection_fct',views.redirection_fct, name='redir_fct'),
#redirection par la fonction as_view
path('redirect1', RedirectView.as_view(url='http://127.0.0.1:8000/blog/redirection_fct')),
path('redirect2', views.redirect_view1),
]
这是我的观点文件:
def about(request):
return render(request, 'about.html', {})
def home(request):
return render(request, 'home.html', {})
#redirection par HttpResponseRedirect
def redirect_view(request):
return HttpResponseRedirect("redirection_fct")
def redirect_view1(request):
return redirect('redir_fct')
def redirection_fct(request):
return render(request, 'redirection.html', {})
我的 URL 模式有问题还是渲染模式有问题?
这是您应用中的 urls.py
吗?你如何将它包含在你的项目中 urls.py
,如果你有一个命名空间,那么你可能需要这样的东西:
def redirect_view1(request):
return redirect('blog:redir_fct')
您可以尝试 运行 从 django shell:
from django.urls import get_resolver
print(get_resolver().reverse_dict.keys())