html - Flask: Getting 400 Bad request on form with bootstrap button groups -


i'm using flask , bootstrap developing small web application. settings page of application, read configuration values sqlite database , draw controls on page according these values, included in html form when change settings , submit form, can post request values written database:

{% extends "base.html" %} {% block content %} <body onload="$('.btn-group').button();"> <form name='form' method='post' action='/conf'>   <div class="container">   <div class="jumbotron">     <h1>settings</h1>     <p class="lead">config</p>     <p><a class="btn btn-lg btn-success" href="/" role="button"><i class="fa fa-home">&nbsp;</i>home</a>     <input type="submit" class="btn btn-lg btn-danger" role="button" name="save" value="apply" /></p>   </div>   <div class="row marketing">     <div class="col-md-4">       <h2>setting 1</h2>       <p>status 1: <span class="badge">{{status}}</span></p>         <div class="btn-group" data-toggle="buttons">           <label class="btn btn-default{{' active' if cloud=="on"}}"><input type="radio" name="cloud" value="on">on</label>           <label class="btn btn-default{{' active' if cloud=="off"}}"><input type="radio" name="cloud" value="off">off</label>         </div>     </div>     <div class="col-md-4">       <h2>setting 2</h2>       <div class="btn-group" data-toggle="buttons">         <label class="btn btn-default{{' active' if res=="358x288"}}"><input type="radio" name="res" value="358x288">358x288</label>         <label class="btn btn-default{{' active' if res=="640x480"}}"><input type="radio" name="res" value="640x480">640x480</label>         <label class="btn btn-default{{' active' if res=="1280x1024"}}"><input type="radio" name="res" value="1280x1024">1280x1024</label>       </div>     </div>   </div> </div> <!-- /container --> </form> {% endblock %} 

, , html code generated (just body):

<body onload="$('.btn-group').button();"> <form name='form' method='post' action='/conf'>     <div class="container">     <div class="jumbotron">         <h1>settings</h1>         <p class="lead">config</p>         <p><a class="btn btn-lg btn-success" href="/" role="button"><i class="fa fa-home">&nbsp;</i>home</a>     <input type="submit" class="btn btn-lg btn-danger" role="button" name="save" value="apply" /></p>     </div>        <div class="row marketing">         <div class="col-md-4">             <h2>setting 1</h2>             <p>status1: <span class="badge">on</span></p>                 <div class="btn-group" data-toggle="buttons">                     <label class="btn btn-default active"><input type="radio" name="cloud" value="on">on</label>                     <label class="btn btn-default"><input type="radio" name="cloud" value="off">off</label>                 </div>           </div>         <div class="col-md-4">             <h2>setting 2</h2>             <div class="btn-group" data-toggle="buttons">                 <label class="btn btn-default"><input type="radio" name="res" value="358x288">358x288</label>                 <label class="btn btn-default active"><input type="radio" name="res" value="640x480">640x480</label>                 <label class="btn btn-default"><input type="radio" name="res" value="1280x1024">1280x1024</label>             </div>         </div>     </div> </div> <!-- /container --> </form> 

when rendering page, settings correctly drawn. e.g., on 3 radio button group values resolution (drawn bootstrap nice set of buttons), proper value, 640x480, appears correctly selected.

however, when submitting form post, i'm getting 400 bad request because settings have not been changed original values loaded not passed post request. but, if click in selected setting (say radio button b - nothing changes because radio buttons had value), field correctly included in request.

know can workaround checking fields present in post request (i.e. keys args dict present), being imbued pythonic spirit, consider pure html form posting should include fields defined within form, no further controls should necessary when processing request. question is, why form fields have been left untouched in page since rendering not included in request? there way force inclusion of these values or missing something?

maybe post piece of rubber duck debugging, fact setting active tag on class not mean field indeed selected?

many in advance


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -