Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

553
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda