[Answered ]-Django crispy form button not showing

2👍

I have absolutely no idea why, but somehow removing

from __future__ import absolute_import

from views fixed the issue for me and now my buttons are showing up.

P.S Found this question, googling for a solution and decided to signup and hopefully help the next one with such a problem :).

👤Axeny

0👍

It’s an old post, but if I made it here on my searches, it’s likely someone else will.

I’m using Django 1.11.9 and django-crispy-forms 1.7.0. You’re on the right track, you actually want to add the ‘submit’ button in init for the class, not within Meta.

See below:

from django.forms import ModelForm
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit
from .models import Author

class NewAuthorForm(forms.ModelForm):
    class Meta:
        model = Author

    def __init__(self, *args, **kwargs):
        super(NewAuthorForm, self).__init__(*args, **kwargs)
        # If you pass FormHelper constructor a form instance
        # It builds a default layout with all its fields
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('save', 'save', css_class = 'btn-primary'))

http://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_forms.html#fundamentals

👤Matt

Leave a comment