python - 使用烧瓶将数据从 html 发送到 python 时遇到问题
问题描述
我有一个 HTML 索引页面,它将输入数据发送到一个 python 脚本,该脚本处理数据并将其输出到第二个 HTML 页面中。在本地主机上,该过程可以正常工作,并且可以根据需要显示数据。但是当我尝试在线托管该过程时,我收到一条错误消息,指出找不到 URL。如果有帮助,我正在使用 Heroku。
提前为任何糟糕的术语道歉。我最近才开始学习如何编码。
第一个 HTML
<form action = "https://webaddress/result" method = "POST">
<h1> Enter info: </h1>
<input type="text" name="info">
<input type="submit" value="Submit"/>
</form>
Python:
from flask import Flask, render_template, request
from bs4 import BeautifulSoup
import requests
# https://doi.org/10.2118/21513-MS
app = Flask(__name__)
@app.route('/')
def student():
return render_template('Trial.html')
@app.route('/result.html',methods = ['POST', 'GET'])
def result():
return render_template("result.html",result = output)
if __name__ == '__main__':
app.run(debug = True)
第一个 HTML 中的输入将被发送到 python 部分进行分解和重新排列(省略该部分,以便 python 代码不会太长),然后再输出到 result.html。这适用于使用http://localhost:5000/和http://localhost:5000/result的本地主机。
当我在 Heroku 上运行它时,我收到错误消息:
未找到
在此服务器上找不到请求的 URL /result。
更新:问题解决了。
解决方案
您的表格是指/result
(无.html
扩展名),但您的路线是/result.html
(带有扩展名)。尝试.html
从您的路线中删除:
@app.route('/result', methods=['POST', 'GET'])
def result():
return render_template("result.html", result=output)
推荐阅读
- python - 如何在 keras 中创建多头卷积层合并为时间维度
- virtual-machine - 启动和停止 Google TPU
- android - Gitlab CI:构建离子应用程序导致“无法创建新的本机线程”错误
- printing - 使用for循环打印任意行数的文本文件的内容(Python3)
- asp.net-mvc - 在 Mvc 中更改 Route Config 中的 url
- flutter - 用于容器的颤振倒角
- python - Django Rest Framework API 管理的最佳分析工具?
- mongodb - mongo - 计数返回未找到文档而不是 0
- python - 查找矩形对象边缘的坐标
- python - ClientConnectorCertificateError