Skip to main content

Flask-WTF companion library for rendering polyglot HTML output

Project description

Flask-WTF-Polyglot

Flask-WTF companion library providing PolyglotForm for polyglot HTML output.

Polyglot markup is a set of rules for how to write HTML. A document that uses polyglot markup is both a valid HTML5 document as well as a well-formed XML document, that can be served with either a text/html or an application/xhtml+xml MIME type.

This package provides the PolyglotForm class, which is built on top of Flask-WTF’s default Form. When using PolyglotForm, fields will be rendered with polyglot markup. For example, given the following form:

from flask_wtf_polyglot import PolyglotForm
from wtforms import BooleanField

class MyForm(PolyglotForm):
    foo = BooleanField("foo", default=True)

Rendering MyForm.foo will result in the following XML-compliant output:

<input checked="checked" id="foo" name="foo" type="checkbox" value="y" />

In contrast, using Flask-WTF’s default Form, the output would be:

<input checked id="foo" name="foo" type="checkbox" value="y">

In addition, this package exports WTForms-Polyglot_’s custom implementation of WTForms’ SubmitField, which renders as a <button> instead of an <input> element. For example:

from flask_wtf_polyglot import PolyglotForm, SubmitField

class MyForm(PolyglotForm):
    foo = SubmitField('Bar')

Produces this output:

<button id="foo" name="foo" type="submit" value="bar">bar</button>

Dependencies

Apart from Flask-WTF, this package relies upon WTForms-Polyglot to produce polyglot markup.

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_wtf_polyglot-0.4.0.tar.gz (3.0 kB view hashes)

Uploaded source

Built Distribution

flask_wtf_polyglot-0.4.0-py3-none-any.whl (3.5 kB view hashes)

Uploaded py3

Supported by

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