2017-02-15 5 views
0

私はpythonスクリプト(rainbow.py)をHTMLボタンで実行しようとしています。私はこれをどうやって行うのか分かりません。私が見つけた答えは私には分かりません。私が望むのは、普通のHTMLスクリプトを通してPythonスクリプトを実行する方法の簡単な説明です。htmlからpythonスクリプトを実行するには

私はこれをラズベリーパイでしようとしています。

HTML(index.htmlを):

<a href="{{ url_for('do_something') }}">Your button</a> 

パイソン(app.py):

+0

はあなたがhttpサーバのどのような種類を使用していますか? –

+0

あなたのポスト(コード)にもっと含めて、おそらく[フレームワーク](http://stackoverflow.com/a/5615268/5645103) –

答えて

1

あなたは、Flaskを通じてのPythonのWebマイクロフレームそれを行うことができます

from flask import Flask, render_template 

app = Flask(__name__) 

@app.route('/') 
def index(): 
    # render your html template 
    return render_template('index.html') 

@app.route('/something') 
def do_something(): 
    # when the button was clicked, 
    # the code below will be execute. 
    print 'do something here' 
    ... 

if __name__ == '__main__': 
    app.run() 

サーバーを起動します。$ python app.py

次にhttp://127.0.0.1:5000に行きます。

ファイル構造:

template\ 
    -index.html 
app.py 
関連する問題