Skip to content

button

Displays a button in the frontend that when clicked calls a python method in the backend.

Basic use

{% htmx_button method_name="my_method" %}
from simmate.website.htmx.components import HtmxComponent

class ExampleView(HtmxComponent):

    def my_method(self):
        # ...
        # run any python code
        # ...
        return  # nothing is done w. return values

Tip

You methods can access and even update other attributes.

For example, a text_input named my_input can be updated via:

from simmate.website.htmx.components import HtmxComponent

class ExampleView(HtmxComponent):
    my_input = "some default value"

    def my_method(self):
        self.my_input = "the button has been clicked!"

Parameters

Parameter Description
method_name The name of the method to call in the backend. Use "submit" to trigger form submission.
Type: str, Default: —
label The display label for the button. If not provided, the method_name may be used as the label.
Type: str, Default: None
show_label Whether to display the label text on the button.
Type: bool, Default: True
theme CSS theme to use for coloring the button. Options are primary, secondary, success, info, warning, danger, and dark.
Type: str, Default: primary
icon Name of the icon to place in the button. Choose from the mdi catalog.
Type: str, Default: None
small Whether to use a small button size.
Type: bool, Default: False
javascript_only If True, the button will only trigger javascript and not a backend call.
Type: bool, Default: False
include CSS selector of elements to include in the request.
Type: str, Default: None
target CSS selector of the element to swap the response into.
Type: str, Default: None
grouped Whether the button is part of a button group.
Type: bool, Default: False