我试图得到什么本质上是拼写检查工具的工作。当我在本地运行时,html在浏览器中显示得很好,但当我输入要传递到python脚本中的数据时,我得到错误:拼写()未定义,即使它是和python部分工作良好。我是Flask应用程序的新手,希望有人能帮助我,谢谢
from flask import Flask, render_template, request
import string
import json
app = Flask(__name__)
@app.route("/")
@app.route("/home")
def home():
return render_template("index.html")
@app.route("/result", methods=['POST', 'GET'])
def result():
inp = request.form.to_dict()
text = inp['text']
s = spell(text)
return render_template("index.html", text=text, suggs=s)
if __name__ == '__main__':
app.run(debug=True, port=5001)
def spell(s):
copy = s
with open('english3.txt') as fh:
l = []
for line in fh:
line = line.rstrip()
l.append(line) ```
... below is just the rest of the python script
[error i get when running: html appears fine in browser but when I enter data to be passed into the python script i get this error.][1]
[1]: https://i.stack.imgur.com/lCB3y.png
尝试在脚本开头定义spell()
函数,然后再调用它:
from flask import Flask, render_template, request
import string
import json
def spell(s):
copy = s
with open('english3.txt') as fh:
l = []
for line in fh:
line = line.rstrip()
l.append(line)
app = Flask(__name__)
@app.route("/")
@app.route("/home")
def home():
return render_template("index.html")
@app.route("/result", methods=['POST', 'GET'])
def result():
inp = request.form.to_dict()
text = inp['text']
s = spell(text)
return render_template("index.html", text=text, suggs=s)
if __name__ == '__main__':
app.run(debug=True, port=5001)