Authentication Django login returns 405 after logging in

Asked

Viewed 24 times

0

The login page after being filled should redirect to the page that requires authentication but returns in the console "POST /login/ HTTP/1.1" 405 0 and in the browser returns to blank login page.

I’m using Django’s User table.
The registration page saves the email name and password, the login screen uses these fields to access I set up Settings that way:

AUTHENTICATION_BACKENDS = [

'django.contrib.auth.backends.ModelBackend',
]
LOGIN_URL = 'login'
LOGIN_REDIRECT_URL ='bemvindo'
LOGOUT_URL ='logout'
LOGOUT_REDIRECT_URL = 'login'

Based View Class:

class Acessar(TemplateView):
    template_name = 'login.html'



class Welcome(LoginRequiredMixin,TemplateView):
    template_name = 'welcome.html'

py urls.py left that way:

from django.urls import path
from  django.contrib.auth import views as autentificacao

    from .views import FormularioViews, Acessar, Welcome
    urlpatterns= [
        path('', FormularioViews.as_view(), name='registrar'),
        path('login/', Acessar.as_view(), name='login'),
        path('logout/', autentificacao.LogoutView.as_view(), name='logout'),
        path('welcome/', Welcome.as_view(), name='bemvindo'),
    ]

In the browser developer tool indicates this message :

Failed to load Resource: the server responded with a status of 405 ()

What is missing in the database is as is_staff true.

html:

<form method="post">
     {% csrf_token %}
<div class="login">
                <input type="text" placeholder="username"  id="id_username" name="username"><br>
                <input type="password" placeholder="password"  name="password" id="id_password"><br>
                <input type="submit" value="Login">
        </div>
    </form>
  • You have the login HTML?

  • has yes.I added

  • As a test change the method post for get in the template: <form method="get"> the status 405 usually occurs when the client sends the request via a verb that the server is not able to receive.

  • switching to get on the console appears like this : "localhost:8000/login/? csrfmiddlewaretoken=W66&username=teste&password=123"". and the page is in the login stop

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.