Why is my django web-app login form not working?

Question:

I’ve tried to add login form to my tasks web-app, but something goes wrong and I can’t login to my created admin user. After click on the login button page just clearing up and my url changes to that. I have no idea how to fix it, help me please.

urls.py

urlpatterns = [
    path('', TaskList.as_view(), name='tasks'),
    path('login/', CustomLoginView.as_view(), name='login'),
    path('logout/', LogoutView.as_view(next_page='login'), name='logout'),
    path('task/<int:pk>', TaskDetail.as_view(), name='task'),
    path('task-create/', TaskCreate.as_view(), name='task-create'),
    path('task-edit/<int:pk>', TaskUpdate.as_view(), name='task-edit'),
     path('task-delete/<int:pk>', TaskDelete.as_view(), name='task-delete'),

]

views.py

class CustomLoginView(LoginView):
    template_name = 'base/login.html'
    fields = '__all__'
    redirect_authenticated_user = True

    def get_success_url(self):
        return reverse_lazy('tasks')

login.html

<h1>Login</h1>
<form metrhod="POST" action="">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Login">
</form>
Asked By: oleqich

||

Answers:

Could it possibly be a spelling error? metrhod="POST"

Try this:


<h1>Login</h1>
<form method="POST" action="">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Login">
</form>

Answered By: Jordan
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.