Skip to main content

Class-based components for Flask

Project description

This module defines classes that can be rendered as "views" in a flask application.

The following example define a form to input some text as a component class (this additionally uses tailwindcss classes):

from flask_composed_views.components import BaseComponent, Form, FormTextInput, Span, PlainText, FormSubmit

class WordInputForm(BaseComponent):
    def __init__(self, id = None, classes = None, csrf_token: str | None = None):
        form = Form(id='word-input-form',
                    classes=classes,
                    csrf_token=csrf_token,
                    action='/',
                    children=[
                        FormTextInput(label=Span(classes="p-2 font-bold",
                                                 children=PlainText('Word:', safe=True,)),
                                      name='word',
                                      id=id,
                                      classes="border-1 border-solid broder-gray-400",
                                      max_len=44),
                        FormSubmit(label=PlainText('Find'),
                                   classes=" ".join([
                                        "rounded-lg px-2 py-1 font-bold bg-yellow-200 hover:bg-yellow-300",
                                        "active:bg-yellow-200 active:border-2 active:border-yellow-200",
                                        "mx-4"
                                   ]))
                    ])
        super().__init__(id, classes, children=[form])

This form is rendered using:

csrf_token = ... # for example, using `flask_wtf.csrf.generate_csrf`
WordInputForm(csrf_token=csrf_token).render()

which could theoretically be used as the output of an @app.route-decorated function. Normally you would embed it within a page layout, etc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_composed_views-0.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_composed_views-0.0.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file flask_composed_views-0.0.1.tar.gz.

File metadata

  • Download URL: flask_composed_views-0.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for flask_composed_views-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c27341ed0d2c220c145b466e7bb149cb05a32c26e8472f319ecd90b2359efb55
MD5 186748eea0e9d1bb019a59a7da4e04b5
BLAKE2b-256 096ab9b95a8535339a16e0d1c942dbffca8ff4ae3da88411d8b3934d399d1e9f

See more details on using hashes here.

File details

Details for the file flask_composed_views-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_composed_views-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ecafc20b1f81a2d27df99f95ec5cd7843c356abdd10d563f386477141cff5dd7
MD5 2b143709683d16ba1c20cd413d1eab11
BLAKE2b-256 360008f3c06708edcd29f8139b9dce3fff71e827992e600b8b71f5519bee4cb4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page