플라스크, 파이썬, mysql에서 웹 앱을 만들고 있습니다. 내 웹 사이트에서 다른 모든 페이지를 볼 때 내 이미지가로드되지만 특정 페이지를 볼 때 이미 작동중인 코드를 사용하여 이미지를로드 할 수 없습니다. 어떤 이유가있을 수 있습니까?플라스크 페이지 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 %}
과 파이썬 파일 :
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 %}
과 파이썬 파일 :
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")'는 실제로 당신의 SQL 표현식으로 전달되는'item' 뷰 함수의'id'입니까? –
당신의'sql' 표현식은 다음과 같아야한다고 생각합니다 :'cursor.execute ("SELECT * FROM shoes where id = % d"% id)' –