I am working on small python application using flask app while clicking the local host link i am not getting internal server error and jinja2.exceptions error I don't know where i did mistake normal python my script is working and giving the result html page not able to read my id_count output how to solve this using python flask here is my script
import numpy as np
from flask import Flask, render_template, request
app = Flask(__name__)
x = np.array([0, 7, 18, 24, 26, 27, 26, 25, 26, 16, 20, 16, 23, 33, 27, 27,
22, 26, 27, 26, 25, 24, 25, 26, 23, 25, 26, 24, 23, 12, 22, 11, 15, 24, 11,
12, 11, 27, 19, 25, 26, 21, 23, 26, 13, 9, 22, 18, 23, 26, 26, 25, 10, 22,
27, 25, 19, 10, 15, 20, 21, 13, 16, 16, 15, 19, 17, 20, 24, 26, 20, 23, 23,
])
@app.route('/')
def main():
return render_template('index.html')
@app.route('/send', methods=['POST'])
def get_count(id_count):
sub_lists = np.split(x, np.where(np.diff(x) <0)[0] 1)
id_count=0
id_list = []
for unit in sub_lists:
if min(unit) ==0 and max(unit)>20 and len(set(unit)) > 1:
id_count = 1
id_list.append(unit)
return id_count
return render_template("index.html",get_count(x))
print("Number of counts: ",get_count(x))
if __name__=="__main__":
app.run(debug=False, port=1223)
``` this is my app.py file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<form action="/data" method = "POST">
<h2> flask app for counting accelerations</h2>
<p>The acceleration count is "{{get_count(x)}}"</p>
</form>
</head>
</html>
how to correct my html page for getting count value
expected out "The acceleration count is 4(some value)"
CodePudding user response:
I think you have to name the parameter in python code :
render_template("index.html",count_result=get_count(x))
And use it in your template, not try to use the python function :
{{ count_result }}
CodePudding user response:
What previos comment send and remove return id_count from get_count function