سؤال

I'm trying to add custom style to my login form in django-allauth. However, I don't know the name of the fields to use.

I want to do something similar to the following code, but with correct field names.

{{ form.email.errors }}
<div class="email">{{ form.email|html_placeholder:"Email" }}</div>
{{ form.password.errors }}
<div class="fieldWrapper">{{form.password|html_placeholder:"password" }}</div>

html_placeholder is nothing but a filter used to add a placeholder attribute to the field

هل كانت مفيدة؟

المحلول

While I was writing this post I found the answer myself.

If you use a default login form (that was my case), you need to find the form that is being used by default. LoginForm is in allauth/acoount/forms.py. There the fields password and remember are explicitly defined, and the field login is added within the __init__ method.

So, in my case it would result:

{{ form.login.errors }}
<div class="login">{{ form.login|html_placeholder:"Email" }}</div>
{{ form.password.errors }}
<div class="fieldWrapper">{{form.password|html_placeholder:"password" }}</div>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top