python - BooleanField usage in WTForms - 400 Bad Request -


getting 400 - bad request booleanfield.

attempting create simple webform mimic python script use @ console. familiar python console - use scripting, i'm new utilizing of wtforms / flask based apps. form 1 drop down - , 1 checkbox. i'm attempting utilize selectfield , booleanfield this.

here form class..

from flask_wtf import form wtforms import selectfield, booleanfield  system_choices = [('storage', 'storage'), ('aix', 'aix'), ('vmware', 'vwmare'), ('sql', 'sql'), ('windows', 'windows')]  class myform(form):     system_select = selectfield('system list', choices=system_choices)     base_select = booleanfield('base create', default=false) 

here view...

from app import app flask import render_template, flash, redirect, request, url_for, session, escape myform import myform fcchecks import fcchecks  app.secret_key = 'not-here'  @app.route('/fcchecks', methods=['get', 'post']) def fcchecks():     myform = myform()      if request.method == 'post':          if request.form['base_select'] not none:             create_base = 'y'         else:             create_base = 'n'          session['whatever'] = request.form         session['base_answer'] = create_base         return redirect(url_for('return_info'))      return render_template('form.html', title="systems",                        form=myform,                        systems=myform.system_select,                        base_select=myform.base_select(required=false))  @app.route('/return', methods=['get', 'post']) def return_info():     mycheck = fcchecks()     messages = session['whatever']     base_answer = session['base_answer']     return render_template('test.html', messages=messages, base_answer=base_answer) 

here template...

{% extends "base.html" %} {% block content %} {{ form.hidden_tag() }} <h1>systems</h1> <h2>base #'s</h2>     <form action="" method="post" name="fcchecks">         {{ systems|e }}         <br>create base {{ base_select }}         <p><input type="submit" value="return_info"></p>     </form> {% endblock %} 

if box on form checked works fine - if left unchecked 400 bad request. know because i'm attempting use session pass information , there no data technically there if box left unchecked - why added in "if" , check_base variable. problem it's still not working.

i've passed entire form off test.html page throws screen - there nothing there base_select if left unchecked. shouldn't there false? need put logic in template check , return false? confused, in head boolean should return true or false - right?


found answer before posted - i'm going go ahead , post in case others having issues. not find documentation in wtforms addressed usage of booleanfield... (sorry if there , didn't find them)...

the problem seems base_select (the booleanfield) not included in form @ if box left unchecked - have check existence...

if 'base_select' in request.form:         create_base = 'y'     else:         create_base = 'n' 


Comments