Reputation: 289
I have this form:
<form class="form-signin" role="form" method="POST" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<input type="text" class="form-control" placeholder="Usuario" required autofocus>
<input type="password" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">
Sign in
</button>
<input type="hidden" name="next" value="{{ next }}" />
<label class="checkbox pull-left">
<input type="checkbox" value="remember-me">
Remember me
</label>
</form>
It has bootstrap classes. I used to have this form:
<form class="form-signin" role="form" method="POST" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="hidden" name="next" value="{{ next }}" />
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
But i was really ugly so i changed it. The problem is that in the new form i have no idea how to implement the authentification of django like i used to do in the ugly version of the form (this one worked fine, i used to write the username and password of the user that was saved in the auth_table of django and it logged in without problems)
But now with the prettier version i don´t know how to do that. I looked around but nothing helps.
Any advice will be really appreciated. Thanks
EDIT
Im using this in my url for this view:
url(r'^login/$', 'django.contrib.auth.views.login',{'template_name':'login.html'}, name = 'login'),
that´s why i was rendering the form in the ugly way
Upvotes: 0
Views: 1351
Reputation: 818
you can customize the fiels of the form :
add attrs like class ,placeholder (all html attrs )
class LoginForm(forms.Form):
username = forms.CharField(max_length=30,widget=forms.TextInput().attrs={'class': 'form-control','placeholder':'Usuario' })
password=forms.CharField(max_length=30,widget=forms.PasswordInput().attrs={'class': 'form-control','placeholder':'Password' })
Upvotes: 2