python 2.7 - Multiple buttons on a flask webapp? -


i'm making first webapp using python , flask, simple calculator i'm stuck trying use more 1 button. @ beginning abe show graph, here python code:

class formulaform(form):     formula = stringfield('formula')     graph = submitfield('graph')  @app.route('/') def calculate():     form = formulaform()     formula = request.args.get('formula','')     points = mp.make_points(formula,0,7)     comp = make_plot(points[0],points[1])     return render_template('index.html',the_script=comp[0],the_div=comp[1],form=form) 

and here html code:

<form method="get" action="">     <br />         {{ form.formula }}     <br />         {{ form.graph }} </form> 

so far good. don't know how add more functionality, example add button shows formula evaluated @ value x. tried adding inputfield , button in form, this:

class formformula(form):     formula = stringfield('formula')     graph = submitfield('graph')     evaluate = stringfield('evaluate_at')     evaluate = submitfield('evaluate') 

but don't know how make view handle 2 different actions. think found solution here works when method "post" , makes page reload don't want. so, there way use multiple buttons in same view?

@app.route('/start' ,methods=['post']) def stop():     "process done here"     return 

your app.py , and html file this

    <script src="static/js/ajax.js"></script>     <script type="text/javascript" language="javascript">     $(document).ready(function() {     $("#start").click(function(event){     $.post(         "/start",         function(data) {             window.alert(data);                      }         );                   });     });  </script>  <button id ="start" type="button" value = "load data">start</button> 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -