python - 在烧瓶中获取 HTML 输入并返回数据
问题描述
我想从特定 URL 的搜索字段中获取输入,并在 Flask 上通过它运行一个函数。但是,即使我只运行 @app.route("/") ,数据也会像我想要的那样返回,但我不断地得到 405 方法是不允许的。
@app.route('/searchcountry', methods = ["GET"])
def single():
return render_template("singlecountry.html")
@app.route('/searchcountry', methods = ["POST"])
def singlecountry():
countrydata = request.form["textfield1"]
alldata = allfacts(countrydata)
return render_template("singlecountry.html", alldata = alldata, countrydata = countrydata)
在这里,我尝试使用我想要的数据更新 /searchcountry。
<!DOCTYPE html>
<html>
<head></head>
<body>
<nav>
<a href="/home">homepage</a>
<a href="/singlecountry">All data on one country</a>
<a href="/comparedcountries">Compare two countries</a>
</nav>
<h1>Data about {{countrydata}}</h1>
<h4>Data is collected from the WHO:<br><a href="https://apps.who.int/gho/portal/uhc-cabinet-wrapper-v2.jsp?id=1010501">Universal Health Coverage</a><br>
As well as the Happy Planet Index:<br><a href="http://happyplanetindex.org/">The Happy Planet Index</a></h4>
<form id="search" name="search" action="." method="POST">
<div id="searchfield">
All data on a country:<br><input type="text" name="textfield1">
</div>
<input type="submit">
</form>
<h3>{{countrydata}}</h3>
{% for data in alldata %}
<tr>
<td>{{data}}</td>
<br>
</tr>
{% endfor %}
</body>
</html>
我的html代码。我知道该功能有效。
解决方案
推荐阅读
- typescript - 类型检查在泛型类中不起作用,但在其派生类中起作用
- reactjs - 如何使特定标签在我的代码中随处可见?
- google-maps - 谷歌地图和可访问性
- c - 对虚拟地址空间和位置无关代码 (PIC) 的困惑
- ruby-on-rails - Rails 服务器尝试在新应用程序上加载 spring 失败(ruby v 2.7.1、rails v 6.0.3.2、MacOS 10.15.5、bundler v 2.1.4、chruby)
- unity3d - Unity Shader 中球体上的等距矩形或径向纹理缩放
- google-sheets - 如何根据两列中的范围搜索两列中的值以返回值(如果两者都匹配)
- google-apps-script - 为什么 onOpen 总是以我的 userMenu 开头而不是我的 adminMenu?
- python - 具有对 python 的索引的 Matlab 结构数组
- jquery - 在控制器中获取空值