from django.http import HttpRequest from django.utils.safestring import mark_safe from django_components import Component, types class FormPage(Component): class Media: js = ( # AlpineJS mark_safe(''), # TailwindCSS "https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4", ) template: types.django_html = """ Form

Submit form

{% component "form" attrs:class="pb-4 px-4 pt-6 sm:px-6 lg:px-8 flex-auto flex flex-col" attrs:style="max-width: 600px;" attrs:@submit.prevent="onSubmit" %} {% fill "field:project" %} {% endfill %} {% fill "field:option" %} {% endfill %} {# Defined both label and field because label name is different from field name #} {% fill "label:description" %} {% component "form_label" field_name="description" title="Marvelous description" / %} {% endfill %} {% fill "field:description" %} {% endfill %} {% fill "append" %}
{% endfill %} {% endcomponent %}
""" # noqa: E501 class View: def get(self, request: HttpRequest): return FormPage.render_to_response(request=request)