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('Wort >', safe=True,)),
                                      name='word',
                                      id=id,
                                      classes="border-1 border-solid broder-gray-400",
                                      max_len=44),
                        FormSubmit(label=PlainText('Suchen'),
                                   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. The result.

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.3.tar.gz (8.0 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.3-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flask_composed_views-0.0.3.tar.gz
  • Upload date:
  • Size: 8.0 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.3.tar.gz
Algorithm Hash digest
SHA256 83fd63d7de3deebaf520f5e47c9b0675ea241489693c236b0624ec61e1605036
MD5 2ed5a1f2343012642940f3ac2e73c046
BLAKE2b-256 28d081321b0005857e35588400145f2262a470fb990c932e3e06d2b92affa756

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flask_composed_views-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b0956c859d17921cb21f6b931759f78a0dd6e5b0744f8c13e5cb4dea04085d51
MD5 748860f9be7776f0dffa0b27a4f184dc
BLAKE2b-256 2e649eec928fda0607db9885231452556b3a7fd49e7da4da4cc1e8faa5f807d0

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