0
私の最初のFlaskプロジェクトでは、Legot for LegendsのRiot GameのAPIを使用して基本的なFlaskアプリケーションを作成したかったのです。私はすべてのAPI処理を処理していますが、出力するのに問題があります。カスタムURLを作成してHTMLフォームデータを出力する
私は1ページのフォームから入力を受け取ります。
<form class="navbar-form navbar-left" action="{{ url_for('current_game_output') }}" method="POST">
<div class="form-group">
<input type="text" class="form-control" placeholder="Summoner Name" name="summoner_name">
<select class="form-control" name="region">
<option value="oce">Oceanic</option>
<option value="na">North America</option>
<option value="euw">Europe West</option>
</select>
</div>
<button type="submit" class="btn btn-default" value="Send">Submit</button>
</form>
また、APIから返されたデータを次のページに出力しようとしています。
{% extends "header.html" %}
{% block body %}
<h3> Team 2 </h3>
<table class="table table-bordered" width="50%">
<tr>
<th width="48%">Summoner Name</th>
<th width="48%">Champion</th>
<th width="4%">Pic</th>
</tr>
{% for player in team1 %}
<tr>
<td>{{ player[0] }}</td>
<td>{{ player[1] }}</td>
<td><img width="20px" src="{{ url_for('static', filename='images/championIcons/') }}{{ player[1].replace(" ", "") }}_Square_0.png"></td>
</tr>
{% endfor %}
</table>
<h3> Team 1 </h3>
<table class="table table-bordered" width="50%">
<tr>
<th width="48%">Summoner Name</th>
<th width="48%">Champion</th>
<th width="4%">Pic</th>
</tr>
{% for player in team2 %}
<tr>
<td>{{ player[0] }}</td>
<td>{{ player[1] }}</td>
<td><img width="20px" src="{{ url_for('static', filename='images/championIcons/') }}{{ player[1].replace(" ", "") }}_Square_0.png"></td>
</tr>
{% endfor %}
</table>
{% endblock %}
私は、ダイナミックな「/ currentgame /地域/ユーザ名」であると、出力ページのURLを好むが、そうしようとすると、エラーを得続けると思います。
私のviews.pyファイル(私のAPIキーを非表示)の関連部分:
@app.route('/header')
def header():
return render_template("header.html")
@app.route('/current')
def current():
return render_template("current.html")
@app.route('/currentgame/<region>/<name>', methods=['POST'])
def current_game_output(region, name):
region = request.form['region']
summoner_name = request.form['summoner_name']
api = RiotAPI('APIKEYGOESHERE', region)
team1, team2 = current_game_data(summoner_name, region, api)
return render_template("output.html",team1=team1,team2=team2)
出力するための最良の方法上の任意のヘルプ/ポインタ/データを返すいただければ幸いです。 ありがとう
OK感謝に変更ルート:これは固定されなければならない迅速なルックスで
。私はあなたがsuggetedと "内部サーバーのエラー"を受け取った修正を試みた。私はログを見て、これらのエラーがあった:http://pastebin.com/1d1zGP9W –
@AConway答えを更新します。今見てください。 –
ありがとう、それはそのエラーを解決しました。残念ながら、このエラーは現在http://pastebin.com/hei1S4B0です。私はURLの変数を設定しようとしていますか? Thanks –