这是一个html链接,我希望在其中解析值并将其发送到列表中的python函数,但是由于某些问题,它以字符串形式返回。
我尝试通过eval()和item.list()将其转换为列表,但无法转换数据类型
@app.route("/verify/")
def verify():
cursor = connection.cursor()
cursor.execute('SELECT `Name`, `Email_ID`, `Phone_No`,`Activation` FROM `user_master` where UTMID = 3')
data = cursor.fetchall()
if data:
print(data)
return render_template('admin/verification.html',data=data)
上面的功能verify是显示项目,下面的功能verifys是获取值并将其更新到表中
@app.route("/verifyscr/<string:item>",methods=['GET',"POST"])
def verifyscr(item):
#item = eval(item)
print("-----",type(item))
if 'pending' in item:
print('pending')
cursor = connection.cursor()
cursor.execute('UPDATE user_master SET Activation = "activated" WHERE Email_ID =%s',(item[1]))
msg = Message('Activation',recipients = ['parikh.madhav1999@gmail.com'])
msg.body = "Hello Flask message sent from Flask-Mail"
mail.send(msg)
connection.commit()
cursor.close()
elif 'activated' in item:
print('activated')
cursor = connection.cursor()
cursor.execute('UPDATE user_master SET Activation = "pending" WHERE Email_ID =%s',(item[1]))
connection.commit()
cursor.close()
return str(item)
{% for item in data %}
<tbody>
<tr>
<td>{{item[0]}}</td>
<td>{{item[1]}}</td>
<td>{{item[2]}}</td>
<td>{{item[3]}}</td>
{% if item[3] == "activated" %}
<td><a href='/verifyscr/{{ item[1],item[3] }}'>Change Status</td>
{% endif %}
{% if item[3] == "pending" %}
<td><a href='/verifyscr/{{ item[1],item[3] }}'>Change Status</td>
{% endif %}
</tr>
</tbody>
{% endfor %}