Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

555
Visualizações
Method Not Allowed (POST): /login/

I'm trying to get the users data using a form which I have in a .html file called login.html. The code for that is:

<form class="register-form" method="POST" action="{% url 'login' %}">
    {% csrf_token %}
    <table>
    <tr>
        <td>Username: </td>
        <td><input type="username" name="username"><br></td>
    </tr>
    <tr>
        <td>Password: </td>
        <td><input type="password" name="password"><br></td>
    </tr>
    </table>
    <br>
    <input type="submit" value="Login" />
</form>

I've already got a database with a bunch of users where username and passwords are stored. I want to create my own login page that checks against that database. What I'm trying to do is essentially get the user to the login.html page and then let the user enter the details and check against the database.

My urls.py looks like this:

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^register$', include('register.urls')),
    url(r'^login/', include('login.urls')),
    url(r'^', include('home.urls')),
]

effectively it goes to the login.urls where the urls.py for that is:

from django.conf.urls import url, include
from django.contrib import admin
from login import views

urlpatterns = [
    url(r'^$', views.LoginPageView.as_view(), name='login'),
]

my views.py is:

from django.shortcuts import render
from django.views.generic import TemplateView
from person.models import Person

class LoginPageView(TemplateView):
    template_name = "login.html"
    def get(self, request, **kwargs):     
        print(request)
        return render(request, 'login.html')

Problem is that when I click the submit button, I want to check against the database, if unsuccessful, show error on the login page, otherwise, successfully authenticate the user and take them to the homepage.

Instead of it working I'm getting: Method Not Allowed (POST): /login/ [21/Apr/2017 14:31:12] "POST /login/ HTTP/1.1" 405 0

Thanks.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You are sending data in POST request and in View.py you are using class based views and in that class you are using get method instead of post method.

views.py

from django.shortcuts import render
from django.views.generic import TemplateView
from person.models import Person

class LoginPageView(TemplateView):
    template_name = "login.html"
    def post(self, request, **kwargs):     
        print(request)
        return render(request, 'login.html')

just replace your get method with post.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda