Search code examples
djangodjango-views

How to use next_page in Django URL path


I have two URL class views from django.contrib.auth:

path('login/', auth_views.LoginView.as_view(
       template_name='accounts/login/login.html'), name='my_login'),


path('logout/', auth_views.LogoutView.as_view(
      template_name='accounts/logout/logout.html', next_page=XXXX), name='my_logout'),

What's the correct syntax to pass to next_page in the LogoutView? E.g.:

next_page='accounts/login/'
next_page='accounts/login/login.html'
next_page=my_login
next_page='my_login'
next_page=reverse_lazy('my_login')

Solution

  • You can pass my_login as value of next_page as per the implementation. Basically its using resolve_url.

    path('logout/', auth_views.LogoutView.as_view(next_page='my_login'), name='my_logout'),
    

    But as @WillemVanOnsem said, you don't need to pass template_name as you will be redirecting to my_login url.