Django HttpResponseRedirect sends request but doesn't actually render?

182 Views Asked by At

I am attempting to redirect a user to http://127.0.0.1:8000/register/Pro/success after a successful registration.

This is my URLs code:

from accounts import views
from django.urls import path,re_path
from django.contrib.auth import views as auth_views

urlpatterns = [
   # path('signup',views.signup_user,name='signup'),
   path('login', views.login_user, name="login"),
   path('logout', views.logout_user,name='custom_logout'),
   re_path(r'^password_reset/$', auth_views.PasswordResetView.as_view(), 
   name='password_reset'),
   re_path(r'^password-reset/email-sent/$', auth_views.PasswordResetDoneView.as_view(), 
   name='password_reset_done'),
    path('password-reset/<uidb64>/<token>/',
    auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
   re_path(r'^password-reset/complete/$', 
   auth_views.PasswordResetCompleteView.as_view(), 
   name='password_reset_complete'),
    path('register/<str:plan>/', views.register, name="register"),
    path('register/<str:plan>/success', views.success, name="redirect")

]

And this is what I am attempting to redirect it with:

return HttpResponseRedirect(f'/register/{plan}/success')

This sends a get request, but it only shows up in the networks tab of developer tools, it doesn't actually render in the same way as if you went to the URL manually.

How would I achieve this?

1

There are 1 best solutions below

0
LaCharcaSoftware On

According to your urls.py, you can use reverse like this:

return HttpResponseRedirect(reverse('redirect', args=(plan,)))

First, you must import the reverse function at the top of views.py:

from django.urls import reverse