Skip to content

Fixed Django 2.1 compatibility due to removal of django.contrib.auth.login()/logout() views. #5510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import django
from django.apps import apps
from django.conf import settings
from django.contrib.auth import views
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.core.validators import \
MaxLengthValidator as DjangoMaxLengthValidator
Expand Down Expand Up @@ -332,3 +333,12 @@ def authenticate(request=None, **credentials):
return authenticate(**credentials)
else:
return authenticate(request=request, **credentials)

if django.VERSION < (1, 11):
login = views.login
login_kwargs = {'template_name': 'rest_framework/login.html'}
logout = views.logout
else:
login = views.LoginView.as_view(template_name='rest_framework/login.html')
login_kwargs = {}
logout = views.LogoutView.as_view()
7 changes: 3 additions & 4 deletions rest_framework/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
from __future__ import unicode_literals

from django.conf.urls import url
from django.contrib.auth import views

template_name = {'template_name': 'rest_framework/login.html'}
from rest_framework.compat import login, login_kwargs, logout

app_name = 'rest_framework'
urlpatterns = [
url(r'^login/$', views.login, template_name, name='login'),
url(r'^logout/$', views.logout, template_name, name='logout'),
url(r'^login/$', login, login_kwargs, name='login'),
url(r'^logout/$', logout, name='logout'),
]