Skip to content

Instantly share code, notes, and snippets.

@doobeh
Last active June 8, 2023 18:09

Revisions

  1. doobeh revised this gist Mar 9, 2020. 3 changed files with 37 additions and 6 deletions.
    14 changes: 14 additions & 0 deletions example.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>
    <form method="post">
    {{ form.hidden_tag() }}
    {{ form.example }}
    <button type="submit">Submit</button>
    </form>
    </body>
    </html>
    18 changes: 12 additions & 6 deletions siecje.py
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,37 @@
    from flask import Flask, render_template
    from flask.ext.wtf import Form, widgets, SelectMultipleField
    from flask_wtf import FlaskForm
    from wtforms import widgets, SelectMultipleField

    SECRET_KEY = 'development'

    SECRET_KEY = 'development'
    app = Flask(__name__)
    app.config.from_object(__name__)


    class MultiCheckboxField(SelectMultipleField):
    widget = widgets.ListWidget(prefix_label=False)
    option_widget = widgets.CheckboxInput()


    class SimpleForm(Form):
    class SimpleForm(FlaskForm):
    string_of_files = ['one\r\ntwo\r\nthree\r\n']
    list_of_files = string_of_files[0].split()
    # create a list of value/description tuples
    files = [(x, x) for x in list_of_files]
    example = MultiCheckboxField('Label', choices=files)


    @app.route('/',methods=['post','get'])
    def hello_world():
    form = SimpleForm()
    if form.validate_on_submit():
    print form.example.data
    print(form.example.data)
    return render_template("success.html", data=form.example.data)
    else:
    print form.errors
    print("Validation Failed")
    print(form.errors)
    return render_template('example.html',form=form)


    if __name__ == '__main__':
    app.run(debug=True)
    app.run(debug=True)
    11 changes: 11 additions & 0 deletions success.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>
    <h1>Success</h1>
    {{ data }}
    </body>
    </html>
  2. doobeh created this gist Jan 29, 2013.
    31 changes: 31 additions & 0 deletions siecje.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    from flask import Flask, render_template
    from flask.ext.wtf import Form, widgets, SelectMultipleField

    SECRET_KEY = 'development'

    app = Flask(__name__)
    app.config.from_object(__name__)

    class MultiCheckboxField(SelectMultipleField):
    widget = widgets.ListWidget(prefix_label=False)
    option_widget = widgets.CheckboxInput()


    class SimpleForm(Form):
    string_of_files = ['one\r\ntwo\r\nthree\r\n']
    list_of_files = string_of_files[0].split()
    # create a list of value/description tuples
    files = [(x, x) for x in list_of_files]
    example = MultiCheckboxField('Label', choices=files)

    @app.route('/',methods=['post','get'])
    def hello_world():
    form = SimpleForm()
    if form.validate_on_submit():
    print form.example.data
    else:
    print form.errors
    return render_template('example.html',form=form)

    if __name__ == '__main__':
    app.run(debug=True)