私はフラスコ/ジンジャーに少し戸惑っています。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)を推薦することができ、非常に有用なチュートリアルを行っている)。 – Cyb3rFly3r
[Ajax](https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started)はあなたが探しているものです。 – dirn