我想創建一個網頁,需要用戶輸入並使用該輸入作爲一個獨立的.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