Cannot display label and field on same line using django-crispy forms

Viewed 3743

I'm trying to place the label of my fields on the left side of the form with the right side having the text input. However, I can't seem to make it work. Here are the settings i've placed.

forms.py

helper = FormHelper()
helper.form_class = 'form-horizontal'
helper.layout = Layout(
    Field('test_field'),
    FormActions(
        Submit('submit', 'Record', css_class='btn btn-primary'),
        Reset('reset', 'Clear', css_class='btn btn-default'),
    )
)

form.html

{% extends 'base.html' %}
{% load crispy_forms_tags %}

{% block page_panel %}
{% crispy form %}
{% endblock %}

The resulting html is like this result

3 Answers

I couldn't get it to work either until I added the following to the settings.py:

CRISPY_TEMPLATE_PACK = 'bootstrap4'

What worked for me with django-crispy-forms was using the helper attribute form_style = 'inline'.

Related