【发布时间】:2020-03-26 07:35:55
【问题描述】:
我有一个函数calculate_full_eva_web(input:dict) 它接收输入字典几个函数应用于这个输入来创建计算字典,计算后我想把这个数据发送到html仪表板,然后把数据发送到html文件我可以在那里玩与神社的东西。我无法这样做,我尝试了几种方法,但烧瓶抛出错误。而且我对ajax不太了解,可能ajax会做我的工作,让我知道。这就是为什么我在这篇文章中标记 ajax 人。 Traceback 也附上。。谢谢
简单来说,我想将数据发送到烧瓶中的 html !请检查我的代码。如果我做错了什么,请告诉我。
imports ...
from other file import other_functions
from other file import other_functions_2
from other file import other_functions_3
app = Flask(__name__, template_folder='templates/')
@app.route("/dashboard")
def calculate_full_eva_web(input:dict):
calculate_gap = other_functions(input)
calculate_matrix = other_functions_2(input)
average = other_functions_3(input)
data = dict{'calculate_gap':calculate_gap, 'calculate_matrix':calculate_matrix,'average':average}
return render_template('pages/dashboard.html', data = data)
if __name__ == "__main__":
app.run(debug=True)
【问题讨论】:
-
您能解释一下如何将字典传递给 /dashboard 端点吗?
-
@DhruvRajkotia 感谢您的回复,我将计算值保存到数据变量中,然后返回 render_template(/pages/dashboard.html, data = data),
-
我认为 input:dict 部分定义错误,你必须像这里一样传递它。 @app.route("/dashboard/") def calculate_full_eva_web(data): data = json.loads(data).你必须像这样通过。
-
@DhruvRajkotia 当我访问 /dashboard 时抛出此错误,然后在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。
标签: python ajax function flask render-html