当我在browsable api中按下登录按钮时,它应该会显示Django REST框架登录页面,但它没有。我得到了这个HTTP响应:"GET /api-auth/ login /?next=/api-auth/ login / HTTP/1.1“2005415
基础URLs.py:
urlpatterns = [
path('', include('RunKeeper.urls')),
path('api-auth/', include('rest_framework.urls')),]rest框架URLs.py:
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'}
app_name = 'rest_framework'
urlpatterns = [
url(r'^login/$', views.LoginView.as_view(), template_name, name='login'),
url(r'^logout/$', views.LogoutView.as_view(), template_name, name='logout'),我已经在安装的应用程序中包含了rest-framework。
我怎样才能解决这个问题?
发布于 2019-03-02 12:41:13
在DEFAULT_AUTHENTICATION_CLASSES类中添加BasicAuthentication和SessionAuthentication类,如下所示。
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
)
}和url模式,如下所示
urlpatterns = [
url(r'^login/$', views.LoginView.as_view(template_name='rest_framework/login.html'), name='login'),
url(r'^logout/$', views.LogoutView.as_view(), name='logout'),
]为什么在logoutView中有登录模板?把那个也去掉。
https://stackoverflow.com/questions/54953216
复制相似问题