Home > Enterprise >  NoReverseMatch at /blog/redirect2
NoReverseMatch at /blog/redirect2

Time:04-11

I'm new to django and I've been trying to test the URLs redirection methods I've tried two options but the return render() keeps giving me this error of no reverse match

this is my urls.py code :


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),

]

and this is my views file :

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', {})

Is there something wrong with my URLs pattern or it is the render one?

CodePudding user response:

Is this the urls.py on your app? How do you include it on your project urls.py, if you have a namespace for it, then you probably need something like:

def redirect_view1(request):
    return redirect('blog:redir_fct')

You can try running from a django shell:

from django.urls import get_resolver
print(get_resolver().reverse_dict.keys())
  • Related