Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (19.9k points)

It should display the Django REST framework login page when i press the login button in the browsable api, but it doesn't. i got this HTTP response : "GET /api-auth/login/?next=/api-auth/login/ HTTP/1.1" 200 5415

Base URLs.py:

urlpatterns = [

path('', include('RunKeeper.urls')),

path('api-auth/', include('rest_framework.urls')),]

rest-framework 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'),]

I've included the rest-framework in the installed apps.

How can i solve the problem

1 Answer

0 votes
by (25.1k points)

Add BasicAuthentication and SessionAuthentication classes in DEFAULT_AUTHENTICATION_CLASSES class as below.

 REST_FRAMEWORK = {

        'DEFAULT_AUTHENTICATION_CLASSES': (

            'rest_framework.authentication.BasicAuthentication',

            'rest_framework.authentication.SessionAuthentication',

        )

    }

And url patterns as below

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'),

]

Why you have login template in logoutView? Remove that one as well.

Related questions

0 votes
1 answer
asked Mar 8, 2021 in Web Technology by Rekha (2.2k points)
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

Browse Categories

...