Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use django-crispy-form FormHelper without modifying Form class

For the sake of consistency I want to use crispy with my login form. I'm using 'django.contrib.auth.views.login' and I'm only coding the template.

The problem is {% crispy form %} doesn’t output submit button nor "next" hidden field.

Is there any way to create FormHelper outside of forms.py ( it's in contrib.auth so I would need to try to extend AuthenticationForm or something like it) an then use it in the template without modifying views.py(also in contrib.auth)

If it would require any ninjitsu with extending classes etc. I will go with pure HTML but if there is a simple way to include 'external' FormHelper on the template level i would regret not asking

like image 272
Lord_JABA Avatar asked Jul 25 '13 12:07

Lord_JABA


1 Answers

I'm not sure why do you need to use {% crispy form %} and not just the crispy filter. I'm using crispy in my login form, overriding the template from django.contrib.auth, this way:

{% load crispy_forms_tags %}

{% block body %}

<form method="post" action="" class="form-signin">{% csrf_token %}
    {{ form|crispy }}
    <div>
    <button type="submit" class="btn btn-primary">{% trans "Log in" %}</button>
    </div>
</form>

{% endblock %}
like image 159
jantoniomartin Avatar answered Oct 26 '22 00:10

jantoniomartin