我想创建一个网页,需要用户输入并使用该输入作为一个独立的.py文件中的参数(所以.py文件需要一个字符串作为参数)形式在瓶不工作
.py文件按其应有的方式工作。但我在html中的表单似乎不正确。我有类似的东西,但没有找到我正在寻找的东西。
这里是我的html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="/" method="get">
<center>
<div>
Keyword: <input type="text" name="search" style="display:inline; width:482px;margin-top:50px" title="Enter a keyword">
<input type="submit" value="Analyze" title="Click to search">
</div>
</center>
</form>
这是确定使用在这种情况下GET。
这里是我的app.py
from flask import Flask
from flask import request
from flask import render_template
from project import my_func
import json, urllib
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template("index.html") #Set render template
@app.route('/results', methods=['GET', 'POST'])
def index():
if request.method == 'GET':
search= request.args.get('search')
my_func(search) #passes the user input into the my_func as a parameter
return render_template('index.html')
else:
return render_template('index.html')
if __name__ == '__main__':
app.debug = True #Uncomment to enable debugging
app.run() #Run the Server
我认为错误是在GET形式,我只是它是否可以做这样。 任何帮助表示赞赏
'投票下来'应该附带一个解释。这将有所帮助。 – ana