Python 2.7 使用下拉过滤器传递excel文档的python
我是Flask的新手。我正在尝试读取excel文件,使用其中一列作为下拉列表作为筛选器来显示2列。运行代码时,会收到一条内部服务器错误消息: 请帮我调试这个代码 下面是我的代码Python 2.7 使用下拉过滤器传递excel文档的python,python-2.7,flask,Python 2.7,Flask,我是Flask的新手。我正在尝试读取excel文件,使用其中一列作为下拉列表作为筛选器来显示2列。运行代码时,会收到一条内部服务器错误消息: 请帮我调试这个代码 下面是我的代码 # Create your views here. import pandas as pd from flask import Flask from flask import request app = Flask(__name__) @app.route('/getfields',methods=['GET','PO
# Create your views here.
import pandas as pd
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/getfields',methods=['GET','POST'])
def getfields(request):
df = pd.read_excel('C:\Users\mysite\Rules.xls')
allfields = df['Field_Name'].unique()
if request.method == 'GET':
return render_template('page1.html',allfields=allfields)
elif request.method == 'POST':
dropValue = request.form.get(['fieldnames'])
dfrows = df.loc[df['Field_Name']==dropValue]
return render_template('page1.html',allfields=allfields,dfrows=dfrows[['rule','rule_type']].to_html())
if __name__ == "__main__":
app.run()
html code:
<!doctype html>
<title>Hello from Flask</title>
<h1>Hello {{ allfields }}!</h1>
<form action="/getfields" method='post'>
<select name='fieldnames'>
{% for val in allfields %}
<option value='{{val}}'>{{val}}</option>
{% endfor %}
</select>
{{dfrows}}
<input type='submit' value='submit'>
</form>
#在此处创建视图。
作为pd进口熊猫
从烧瓶进口烧瓶
从烧瓶进口请求
app=烧瓶(名称)
@app.route('/getfields',methods=['GET','POST']))
def getfields(请求):
df=pd.read\u excel('C:\Users\mysite\Rules.xls')
allfields=df['Field_Name'].unique()
如果request.method==“GET”:
返回呈现模板('page1.html',allfields=allfields)
elif request.method==“POST”:
dropValue=request.form.get(['fieldnames'])
dfrows=df.loc[df['Field_Name']==dropValue]
将呈现模板('page1.html',allfields=allfields,dfrows=dfrows[['rule','rule\u type']]返回到\u html()
如果名称=“\uuuuu main\uuuuuuuu”:
app.run()
html代码:
你好,我是Flask
你好{{allfields}}!
{所有字段%中val的百分比}
{{val}}
{%endfor%}
{{dfrows}}
在调试模式下运行应用程序(app.Run(debug=True)
),这样每当出现错误时,您就可以获得详细的堆栈跟踪。错误说明:“get/getfields HTTP/1.1”404不能被删除。“内部服务错误”的代码为500,它可能是500或404。您现在看到的是不同的情况。我再次运行代码时出现以下错误:未找到服务器上未找到请求的URL。如果您手动输入URL,请检查拼写并重试。