2👍
✅
Django comes with authentication views, you should use these if possible instead of writing your own.
You already included the built-in login view in your URL patterns.
url(r'^login/$', auth_views.login, {'template_name': 'account/login.html'}, name='login'),
Therefore you don’t need your user_login
view, so I would remove it. I have removed your custom authentication form because it is not required. The default authentication form already has the username and password fields. You have broken the clean_
methods because you don’t return a value.
Next, fix the form’s action
in your template. Currently you are submitting the form data to the home
view. You should send it to the login
view.
<form class="form-horizontal" role="form" method="POST" action="{% url 'login' %}">
Finally, I would add LOGIN_URL = 'login'
to your settings, then you can simplify the code that uses login_required
to the following:
@login_required
def home(request):
...
Source:stackexchange.com