私はどこにでも見てきましたが、本当に良い答えは見つかりませんでした。 私はPythonでローカルHTMLページを生成しています。そこからフォームからデータを読み込み、これをPythonスクリプトの入力として使用し、そこから適切に戻ります。pythonスクリプトの入力としてhtmlフォームを使用する簡単なソリューション
f = open('testapi.html','w')
message = """
<html>
<head>
<title></title>
<link rel="stylesheet" href="Bootstrap/bootstrap-3.3.5-dist/css/bootstrap.css" type="text/css"/>
<script>
</script>
</head>
<body>
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-3">
<p>Search for best deals</p>
<form name="deals" action="">
<table>
<thead></thead>
<tbody>
<tr> <th>Title </th> <th><input type="text" id="Title" value=""><br></th> </tr>
<tr> <th>Lowest price</th> <th><input type="text" id="LowerPrice" value=""><br></th> </tr>
<tr> <th>Highest price</th> <th><input type="text" id="UpperPrice" value=""><br></th> </tr>
<tr> <th>Sale only</th> <th><input type="checkbox" id="OnSale" value=""></br></th> </tr>
</tbody>
</table>
<p>Sort by:</p>
<input type="radio" name="sort" id="DealRating" value="a">Deal rating<br>
<input type="radio" name="sort" id="Title" value="b">Title<br>
<input type="radio" name="sort" id="Price" value="c">Price<br>
<input type="radio" name="sort" id="Release" value="d">Release<br>
<input type="button" name="Sumbit" value="Submit" onClick="">
</form>
<p> Note: all fields are optional, fill only what you are intrested in.</p>
</div>
<div class="col-md-2">
<p> OR </p>
</div>
<div class="col-md-3">
<p>Search for your favourite games<p>
<form name="games" action="">
<table>
<thead></thead>
<tbody>
<tr><th>Title</th> <th><input type="text" id="GameTitle" value=""></br></th></tr>
</tbody>
</table>
<input type="button" name="Sumbit" value="Submit" onClick="">
</form>
<p> Note: all fields are optional, fill only what you are intrested in.</p>
</div>
<div class="col-md-2">
</div>
</div>
</body>
</html>
"""
f.write(message)
f.close()
私の質問は以下のようになります。私は、APIの検索でそれを処理するために、そのフォームの入力を使用してからこのページに戻って結果を返すことができますか? OR 最終的には、私のページからnpythonスクリプトを実行して結果を表示するには?
注:これにはPythonを使用する必要があります。これは私のプロジェクトの必要条件です。
サーバが必要なのでCGIを避けたいと思います。サーバーを設定しなくてもローカルで実行したいと考えています。 – Trykon
@ Trykonそれでは、あなたがしたいことが分かりません。誰がこのフォームに記入する必要がありますか?どうして?あなたがしたいのは、データをAPIに送信するだけで、HTMLのオーバーヘッドなしにデータを送信するだけです。 – Odi
このHTMLは、私がPythonで初心者であり、Pythonでguiが私の手の届かないところにいるので、GUIとして動作する – Trykon