12๐
โ
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'}),
๐คp3y4m
6๐
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.
๐คAlasdair
- Django โ Objects for business hours
- <django.db.models.fields.related.RelatedManager object at 0x7ff4e003d1d0> is not JSON serializable
- Email integration
- Ignore a specific test using Django
Source:stackexchange.com