Django custom login page Django custom login page django django

Django custom login page


You can use login view, which is provided by Django. So your login.html should look like that example.

<form class="login" method="POST" action="/login/">  {% csrf_token %}  {{form.as_p}}  <li><input type="submit" class="logBut" value="Log in"/></li>  </form>

And remember urls.py !

url(r'^login/$','django.contrib.auth.views.login', {'template_name': '/login.html'}),


The correct approach is to use forms, instead of fetching the variables directly from request.POST. Django will then validate the form data, and display errors when the form is rendered in the template. If a form field is required, then Django will automatically display an error when the field is empty, you don't even need to write a clean_<field_name> method for this.

Django already has a built in login view. The easiest approach is to use this rather than writing your own. If you still want to write your own view, you will still find it useful to look at how Django does it.