4

Are there no next_page or template_name arguments in Django 2.2 for logout and login? I got these errors when upgraded from Django 1.11 to Django 2.2!!

This is my urls.py

from django.contrib.auth import logout

url(r'^logout/$',logout, {'next_page': '/'},name='logout'),

The logout_url from settings.py is

LOGOUT_URL = '/'

I keep getting this error:

TypeError at /portal/logout/
logout() got an unexpected keyword argument 'next_page'
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 2.2
Exception Type: TypeError
Exception Value:    
logout() got an unexpected keyword argument 'next_page'

The same thing happened with login too

urls.py

from django.conf.urls import url
from landing.views import landing_validation

app_name='landing'
urlpatterns = [
    url(r'^$', landing_validation, name='landing')
]

views.py

def landing_validation(request):
  login_response = login(request, template_name='landing.html')

  return login_response

TypeError at /
login() got an unexpected keyword argument 'template_name'
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 2.2
Exception Type: TypeError
Exception Value:    
login() got an unexpected keyword argument 'template_name'
Venkatesh Gotimukul
  • 741
  • 1
  • 9
  • 30
  • 1
    There are a lot of changes from 1.11; especially with the way urls are served. I'd start here: https://docs.djangoproject.com/en/2.2/releases/2.0/ This site had good info too: https://consideratecode.com/2018/05/02/django-2-0-url-to-path-cheatsheet/ Hope this helps. – Jamie Piscitelli Apr 22 '19 at 23:50
  • How's it going? Did you find a solution? :D – Ersain Nov 19 '19 at 12:16

1 Answers1

6

If you're still wondering about a solution for that issue after migrating, here is the simplest one:

In settings.py add:

LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'

home refers to your home page route name or just

LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'  # Or maybe another URL you want to set.

and then in your urls.py change your route to be like this:

url(r'^logout$', LogoutView.as_view(),  name='logout'),

LogoutView comes is imported from django.contrib.auth.views import LogoutView

Ramy M. Mousa
  • 5,727
  • 3
  • 34
  • 45