How to update an existing Python Flask web page based on form input?

I am trying to build a prediction web application with Flask. The app should take in user input, process it through a python trained model, then display the results as a chart beside the input form.

My code looks like this:

HTML Form:

<form class = "prediction-options" method = "post" action = "/prediction/results">   <!--the input fields--> </form> 


@app.route("/") def main():     return render_template('index.html')      @app.route("/prediction/results", methods = ['POST']) def predict():     input_aqi = float(request.form['aqi'])/272     input_pm2_5 = float(request.form['pm2_5'])/224     input_pm10 = float(request.form['pm10'])/283     input_so2 = float(request.form['so2'])/36     input_no2 = float(request.form['no2'])/110     input_co = float(request.form['co'])/1.83     input_o3 = float(request.form['o3'])/124     input_list = [[input_aqi,input_pm2_5,input_pm10,input_so2,input_no2,input_co,input_o3]]       output_acute_bronchitis = model_acute_bronchitis.predict(input_list)     output_asthma = model_asthma.predict(input_list)     output_asthmatic_bronchitis = model_asthmatic_bronchitis.predict(input_list)     output_aurti = model_aurti.predict(input_list)     output_bronchitis = model_bronchitis.predict(input_list)     output_pneumonia = model_pneumonia.predict(input_list)      d = collections.OrderedDict()     d['acute_bronchitis'] = output_acute_bronchitis[0]     d['asthma'] = output_asthma[0]     d['asthmatic_bronchitis'] = output_asthmatic_bronchitis[0]     d['aurti'] = output_aurti[0]     d['bronchitis'] = output_bronchitis[0]     d['pneumonia'] = output_pneumonia[0]      prediction = jsonify(d)     return prediction 

Right now, I have managed to take in the user input and render the predicted results on the '/prediction/results' page. How can I get the results to show up on the '/' page? I tried to do this:

@app.route("/", methods = ['POST','GET']) def main():     if request.method == 'POST':         def predict():            #predict function that returns prediction     return render_template('index.html') 

But I always get a socket.error: [Errno 32] Broken pipe error message. What should I do?


Category: python Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.537 (s). 12 q(s)