Skip to content

Commit 1a526c1

Browse files
felixxmcarltongibson
authored andcommitted
Fixed Django 2.1 compatibility due to removal of django.contrib.auth.login()/logout() views. (#5510)
1 parent 320f10a commit 1a526c1

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

rest_framework/compat.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import django
1212
from django.apps import apps
1313
from django.conf import settings
14+
from django.contrib.auth import views
1415
from django.core.exceptions import ImproperlyConfigured, ValidationError
1516
from django.core.validators import \
1617
MaxLengthValidator as DjangoMaxLengthValidator
@@ -332,3 +333,12 @@ def authenticate(request=None, **credentials):
332333
return authenticate(**credentials)
333334
else:
334335
return authenticate(request=request, **credentials)
336+
337+
if django.VERSION < (1, 11):
338+
login = views.login
339+
login_kwargs = {'template_name': 'rest_framework/login.html'}
340+
logout = views.logout
341+
else:
342+
login = views.LoginView.as_view(template_name='rest_framework/login.html')
343+
login_kwargs = {}
344+
logout = views.LogoutView.as_view()

rest_framework/urls.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
from __future__ import unicode_literals
1616

1717
from django.conf.urls import url
18-
from django.contrib.auth import views
1918

20-
template_name = {'template_name': 'rest_framework/login.html'}
19+
from rest_framework.compat import login, login_kwargs, logout
2120

2221
app_name = 'rest_framework'
2322
urlpatterns = [
24-
url(r'^login/$', views.login, template_name, name='login'),
25-
url(r'^logout/$', views.logout, template_name, name='logout'),
23+
url(r'^login/$', login, login_kwargs, name='login'),
24+
url(r'^logout/$', logout, name='logout'),
2625
]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy