sajid
sajid

Reputation: 893

django-crispy-form does not render the submit button and does not render the form action attribute

I am trying to use django-cripsy-for to customize my forms. But it seems that crispy form is somehow not rendering the submit button and the form action attribute. Here is template i am rendering the form at.(login.html)

{% extends '_base.html' %}
{% block content %}
{{ login_error_message }}

    {% load crispy_forms_tags %}
    {% crispy form form.helper  %}

{% endblock %}

And here is the view

class LoginView(FormView):
    form_class = LoginForm
    template_name = "login.html"
    success_url = reverse_lazy('home')

    def form_valid(self, form):
        email = form.cleaned_data['email']
        password = form.cleaned_data['password']
        referrer = self.request.POST.get('referrer')
        user = authenticate(email=email, password=password)

        if user is not None:
            # if user.is_active:
            login(self.request, user)
            if referrer !="":
                self.success_url = referrer
            return super(LoginView, self).form_valid(form)
        else:

            return render(self.request, "login.html", {'form': form, 'login_error_message': "Invalid username and password."})

    def get_context_data(self, **kwargs):
        result = super(LoginView, self).get_context_data( **kwargs)
        param = self.request.GET.get('next', '')
        result.update({'param': param})
        return result

And here is my form class

class LoginForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id-form'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = 'login'

    email = forms.EmailField(max_length=100)
    password = forms.CharField(max_length=100)

What am I missing ? Please help .

Upvotes: 0

Views: 745

Answers (2)

scable
scable

Reputation: 4084

Regarding the missing submit button: You have to add it first!

self.helper.add_input(Submit('submit', 'Submit'))

As can be seen in the 4th listing of the Fundamentals documentation

Upvotes: 1

Isaac Ray
Isaac Ray

Reputation: 1361

From the Django Docs (https://docs.djangoproject.com/en/1.8/topics/templates/):

{# this won't be rendered #}

You are outputting your form as a series of Django comments in your template for some reason. Why?

Upvotes: 0

Related Questions