Flask-Appbuilder POST from form None

1.1k views Asked by At

My POST sends the data of the RadioField that was chosen, but in Flask I only get 'None' for the form.display.data . The GET works fine, and RadioFields are on the page, when I click 'Submit' the display variable is sent in POST with the correct choice.

How do I get the actual data for the POST?

views.py

class Items(SimpleFormView):
    route_base = "/manage"
    datamodel = SQLAInterface(TerminalA82)
    message = "Please make a seslection"
    form = List_Items()

    myList = Controller.generate #<-- external function provides list
    form.display.choices = myList

    @expose('/manage', methods=['GET'])
    @has_access
    def this_form_get(self):
        return self.render_template('list_items.html', param1='Items', form=self.form)

    @expose('/manage', methods=['POST'])
    @has_access
    def this_form_post(self):
        return self.render_template('blank.html', param1=str(self.form.display.data))

The POST renders 'None' on the page.

forms.py

class List_Items(Form):
    display = RadioField('Items', choices=[], coerce=int)

list_items.html (Template)

{% extends "appbuilder/base.html" %}
{% block content %}
<h3>{{param1}}</h3>
<form method="post">
    {{ form.display }}
    <input type="submit" value="Submit">
</form>
{% endblock %}

myList content

>>> print myList
[('5', 'MyBAsic'), ('9', 'Cloudtest'), ('12', 'Test2'), ('15', 'NHLS-Test'), ('18', 'HSRC-Test')]
>>> 

blank.html

{% extends "appbuilder/base.html" %}
{% block content %}
    <p>{{param1}}</p>
{% endblock %}
1

There are 1 answers

6
Shiv On BEST ANSWER

Yes, if you see flask documentation then you need to access that piece of data as request.form['Items'] not as form.display.data.