Question

I'm using django-crispy-forms to generate a Bootstrap-compatible form. For the form submission, I have the following code in my forms.py:

FormActions(
    Submit('convert', 'Save changes', css_class="btn-primary"),
    HTML(' | '),
    Submit('cancel', 'Cancel'),
)

Instead of the Submit text reading "Save changes", I'd rather leverage the template variable {{ function }} which is passed from my view. Sometimes, this variable reads "Edit Task." Sometimes it reads "Create Task."

Is there a way to include a template variable in the button's text? I tried the following:

FormActions(
    Submit('convert', 
        HTML(""" {{ function }} """),
        css_class="btn-primary"),
    HTML(' | '),
    Submit('cancel', 'Cancel'),
)

but the button output read:

<crispy_forms.layout.HTML object at 0x0331C970>
Was it helpful?

Solution

No, this not supported currently. I'm planning on working on the project his weekend and I will look at this.

Update 2012/9/16

Since version 1.2.0 you can do:

Submit("button.name", '{{ context_var }}')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top