Crispy forms not showing bootstrap and save/submit button

886 views
Skip to first unread message

Taufiq Rahman

unread,
Jul 13, 2017, 8:26:50 AM7/13/17
to Django users
Hey guys. I'm having trouble with Crispy forms with my models. The form shows up plain without the bootstrap and there seems to be no save button which i need to save data to my model. I have tried many ways and tutorials but have failed. Any help would be highly appreciated! 

forms.py
from django import forms
from crispy_forms.helper import FormHelper
from .models import Plot


class PlotForm(forms.ModelForm):
    helper = FormHelper()
    helper.form_tag = False
    helper.form_method = 'POST'

    class Meta:
        model = Plot
        fields = '__all__'

the html:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Plot form</title>
</head>
<body>
    {% load crispy_forms_tags %}

    {% block content %}
       {% crispy form %}
    {% endblock %}
</body>
</html>



views.py
def plot_form(request):
    return render(request, 'plot_form.html', {'form': PlotForm()})


JHeasly

unread,
Jul 13, 2017, 1:36:35 PM7/13/17
to Django users
Hello Taufiq —

Have you tried using the "instance level helper"?
See http://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_forms.html#crispy-tag-with-forms
From the docs link above:
from crispy_forms.helper import FormHelper

class ExampleForm(forms.Form):
    [...]
    def __init__(self, *args, **kwargs):
        super(ExampleForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()


Hope this helps,
John

JHeasly

unread,
Jul 13, 2017, 1:42:46 PM7/13/17
to Django users
Also, do you have any FormActions defined? That's where the Bootstrap button comes from:
http://django-crispy-forms.readthedocs.io/en/latest/layouts.html#bootstrap-layout-objects

Gabriel - Iulian Dumbrava

unread,
Jul 26, 2017, 12:05:49 PM7/26/17
to Django users
Maybe it's because you have instructed crispy to not generate the form tag and you have not added it yourself in the HTML code.
Reply all
Reply to author
Forward
0 new messages