django_htmx_modal_forms package

class django_htmx_modal_forms.HtmxModalCreateView(**kwargs)[source]

Bases: HtmxModalFormMixin, CreateView

View for creating objects via modal forms.

On successful form submission, the page will be refreshed to show the newly created object.

form_valid(form: BaseForm) HttpResponse[source]

Save form and refresh page on success.

class django_htmx_modal_forms.HtmxModalFormMixin(**kwargs)[source]

Bases: View

Base mixin for modal form handling with HTMX and Bootstrap.

This mixin provides the core functionality for handling forms in Bootstrap modals using HTMX for dynamic updates.

Attributes:

template_name (str): Template for the full modal structure form_template_name (str): Template for just the form content modal_size (str): Bootstrap modal size class (sm, lg, xl) modal_title (str): Custom modal title override

element_id_prefix: str | None = None
element_id_suffix: str | None = None
form_invalid(form: BaseForm) HttpResponse[source]

Handle invalid form submission.

form_template_name = 'htmx_modal_forms/_form_content.html'
get(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse[source]

Handle GET requests and trigger modal show.

get_context_data(**kwargs: Any) dict[str, Any][source]

Add modal-specific context.

get_element_id() str[source]

Get the element ID for the form target.

This method can be overridden to customize the ID generation. By default, it uses the pattern: “{prefix}{model_name}-{pk}{suffix}”

get_modal_size() str[source]

Get the Bootstrap modal size class.

Override this method to customize the modal size.

get_modal_title() str[source]

Get the title for the modal.

Override this method to customize the modal title.

modal_size: str = 'lg'
modal_title: str | None = None
template_name = 'htmx_modal_forms/_modal_form.html'
class django_htmx_modal_forms.HtmxModalUpdateView(**kwargs)[source]

Bases: HtmxModalFormMixin, UpdateView

View for updating objects via modal forms.

On successful form submission, the target element will be updated with the new object details.

Attributes:

detail_template_name (str): Template for rendering updated object details

detail_template_name: str | None = None
form_valid(form: BaseForm) HttpResponse[source]

Save form and update the page with new object details.

get_detail_template_name() str[source]

Get the template name for rendering object details.

Override this method to customize the template selection.

Subpackages

Submodules

django_htmx_modal_forms.apps module

class django_htmx_modal_forms.apps.HtmxModalFormsAppConfig(app_name, app_module)[source]

Bases: AppConfig

App config for Django Htmx Modal Forms.

name = 'django_htmx_modal_forms'
verbose_name

django_htmx_modal_forms.conf module

These are the available settings.

All attributes prefixed HTMX_MODAL_FORMS_* can be overridden from your Django project’s settings module by defining a setting with the same name.

class django_htmx_modal_forms.conf.AppSettings(HTMX_MODAL_FORMS_ENABLED: bool = True)[source]

Bases: object

Access this instance as .conf.app_settings.

HTMX_MODAL_FORMS_ENABLED: bool = True

Whether the app is enabled (dummy setting to demo usage).

django_htmx_modal_forms.main module

django_htmx_modal_forms.main.add(n1: int, n2: int) int[source]

Add the arguments.

django_htmx_modal_forms.main.is_enabled() bool[source]

Example usage of app settings.

django_htmx_modal_forms.views module

Django HTMX Modal Forms - Class-based views for HTMX-powered Bootstrap modals.

class django_htmx_modal_forms.views.HtmxModalCreateView(**kwargs)[source]

Bases: HtmxModalFormMixin, CreateView

View for creating objects via modal forms.

On successful form submission, the page will be refreshed to show the newly created object.

form_valid(form: BaseForm) HttpResponse[source]

Save form and refresh page on success.

class django_htmx_modal_forms.views.HtmxModalFormMixin(**kwargs)[source]

Bases: View

Base mixin for modal form handling with HTMX and Bootstrap.

This mixin provides the core functionality for handling forms in Bootstrap modals using HTMX for dynamic updates.

Attributes:

template_name (str): Template for the full modal structure form_template_name (str): Template for just the form content modal_size (str): Bootstrap modal size class (sm, lg, xl) modal_title (str): Custom modal title override

element_id_prefix: str | None = None
element_id_suffix: str | None = None
form_invalid(form: BaseForm) HttpResponse[source]

Handle invalid form submission.

form_template_name = 'htmx_modal_forms/_form_content.html'
get(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse[source]

Handle GET requests and trigger modal show.

get_context_data(**kwargs: Any) dict[str, Any][source]

Add modal-specific context.

get_element_id() str[source]

Get the element ID for the form target.

This method can be overridden to customize the ID generation. By default, it uses the pattern: “{prefix}{model_name}-{pk}{suffix}”

get_modal_size() str[source]

Get the Bootstrap modal size class.

Override this method to customize the modal size.

get_modal_title() str[source]

Get the title for the modal.

Override this method to customize the modal title.

modal_size: str = 'lg'
modal_title: str | None = None
template_name = 'htmx_modal_forms/_modal_form.html'
class django_htmx_modal_forms.views.HtmxModalUpdateView(**kwargs)[source]

Bases: HtmxModalFormMixin, UpdateView

View for updating objects via modal forms.

On successful form submission, the target element will be updated with the new object details.

Attributes:

detail_template_name (str): Template for rendering updated object details

detail_template_name: str | None = None
form_valid(form: BaseForm) HttpResponse[source]

Save form and update the page with new object details.

get_detail_template_name() str[source]

Get the template name for rendering object details.

Override this method to customize the template selection.