@app.route('/select/<username>')
def select(username):
db = MySQLdb.connect("localhost","myusername","mypassword","mydbname" )
cursor = db.cursor()
cursor.execute("SELECT * FROM p_shahr")
data = cursor.fetchall()
db.close()
return render_template('select.html', data=data)
이 스크립트에서 선택 쿼리를 편집하여
SELECT * FROm p_shahr WHERE os = username
URL에서 오는 것으로 설정 하기 위해 위 의 where 절 을 포함하도록 쿼리를 편집하려면 어떻게해야 합니까?os
username
쿼리에서 자리 표시자를 사용하고 매개 변수를 튜플로 execute
.
@app.route('/select/<username>')
def select(username):
db = MySQLdb.connect("localhost","myusername","mypassword","mydbname" )
cursor = db.cursor()
query_string = "SELECT * FROM p_shahr WHERE os = %s"
cursor.execute(query_string, (username,))
data = cursor.fetchall()
db.close()
return render_template('select.html', data=data)
그러나 [URL에서 DB로 직접 데이터 전달]은 매우 순진하고 공격을 받기 쉬운 접근 방식입니다. 보다
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다