我是Flask/Jinja的新手,有點困惑。使用Flask,Jinja2,HTML更新按鈕上的頁面
我有一個文本輸入框,一個按鈕和一個無序列表的index.html文件。我也有一個main.py文件,其中包含一些可以輸入的函數。
當我按下按鈕時,我想在輸入字段中輸入文本,將文本傳遞給我的python文件(它將執行一些處理/ API調用),然後將列表傳遞迴HTML文件, - 提交頁面。我該如何做到這一點?
這裏是我的代碼片段:
index.html中:
#This is where I want to get the input from
<input type="text" style="text-align:center;">
#This is the button that should generate the list when I press it
<li><a href="#content" class="button big special">Search</a></li>
在main.py:
@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return 'Hello World!'
def doesArticleExist(topic):
foundTopics = wikipedia.search(topic)
if (len(foundTopics) > 0):
return foundTopics
return ["No topics were found! Your topic is new!"]
任何幫助將不勝感激!
有瓶上存在大量的文檔,涵蓋這種例子在網絡上。我的建議是從一個很好的教程開始。我可以推薦Miguel Grinberg(http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world),他也寫了一本書,並做了一些非常有用的教程(參見YouTube )。 – Cyb3rFly3r
[Ajax](https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started)是您正在尋找的。 – dirn