フラスコ、python、mysqlでWebアプリケーションを作成しています。私のウェブサイト上の他のすべてのページを見るとイメージが読み込まれますが、特定のページを表示すると、既に動作しているコードを使用してイメージを読み込むことはできません。これには何らかの理由がありますか?1つのフラスコページ以外のすべてに表示される画像
私の作業のいずれかのページのためのコード:
{% extends "base.html" %}
{% block content %}
<!-- home style sheet -->
<link rel="stylesheet" type="text/css" href="/static/css/home.css">
{% for index in range(0, shoes|count, 3) %}
<div class="row">
<div class="col-md-4">
<a href="shop/item/{{ shoes[index][0] }}">
<h4>{{ shoes[index][1] }}</h4>
<img src="{{ shoes[index][7] }}" alt="" width="250px" height="150px">
</a>
</div>
{% if shoes|count - index >= 2 %}
<div class="col-md-4">
<a href="shop/item/{{ shoes[index][0] + 1 }}">
<h4>{{ shoes[index + 1][1] }}</h4>
<img src="{{ shoes[index + 1][7] }}" alt="" width="250px" height="150px">
</a>
</div>
{% endif%}
{% if shoes|count - index >= 3 %}
<div class="col-md-4">
<a href="shop/item/{{ shoes[index][0] + 2 }}">
<h4>{{ shoes[index + 2][1] }}</h4>
<img src="{{ shoes[index + 2][7] }}" alt="" width="250px" height="150px">
</a>
</div>
{% endif%}
</div>
{% endfor %}
{% endblock %}
とそのPythonのファイル:
from app import app, mysql
from flask import render_template
@app.route('/shop')
def shop():
cursor = mysql.connect().cursor()
cursor.execute("SELECT * FROM shoes")
data = cursor.fetchall()
return render_template('shop.html', shoes = data)
今失敗ページ:
{% extends "base.html" %}
{% block content %}
<!-- home style sheet -->
<link rel="stylesheet" type="text/css" href="/static/css/home.css">
<div class="row">
<div class="col-md-5">
<img src="{{ item[0][7] }}" alt="" width="250px" height="150px">
</div>
</div>
{% endblock %}
とそのPythonのファイル:
from app import app, mysql
from flask import render_template
@app.route('/shop/item/<id>')
def item(id):
cursor = mysql.connect().cursor()
cursor.execute("SELECT * FROM shoes WHERE id=id")
data = cursor.fetchall()
return render_template('item.html', item = data)
ご協力いただきありがとうございます。
EDIT;
空のイメージの要素を調べると、作業用ページと同じsrc URLがあるため、SQLデータがこのページに正しく送信されていることがわかります。また、取得したローの他のすべての属性は正しいです。 私のSQLテーブルには次のようになります。あなたのitem
ビュー機能で
id | name | size | price | primarycolor | secondarycolor | othercolor | img |
+----+----------------------------------+------+--------+--------------+----------------+------------+-------------------------+
| 1 | 2013 Air Jordan 11 Retro | 10.0 | 215.00 | black | gamma blue | NULL | static/pics/gamma.png
あなたのSQLテーブル行の例や 'print'の' data'にはどのようなものがありますか? –
そしてこの式で 'cursor.execute(" SELECT * FROM shoes WHERE id = id ")'はあなたの 'item'ビュー関数の' id'を実際にSQL式に渡していますか? –
あなたの 'sql'式は次のようになるはずです:' cursor.execute( "SELECT * FROM shoes WHERE id =%d"%id) ' –