Я новичок в этом питоне и фляге.
Моя проблема в том, как вернуть значения из запроса MySQL для показа в html. В настоящее время я решаю эту проблему, но возвращаемая информация в моем запросе включает {{databasecolumnname: data here}}
Примерно так:
0 {'username': 'unu'} 0 {'email': '1@1.com'}
1 {'username': 'dos'} 1 {'email': 'two@two.com'}
2 {'username': 'test1'} 2 {'email': 'testtest@test.com'}
Все, что я хочу сделать, - это удалить {} иимя столбца базы данных. Есть ли способ сделать это с моим текущим кодом?
Я хочу, чтобы возврат был таким:
0 unu 1@1.com
1 dos two@two.com
2 test1 testtest@test.com
Я только учусь, как кодировать.
Я пытался извлечь и зациклить его, также использовал sql alchemy. Все, что я хочу сделать, это вернуть его чисто без открытой скобки и имени столбца
У меня есть этот код на моем main.py
@app.route ('/ flaskapp / profile2')
cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute("SELECT username FROM accounts")
data = cursor.fetchall()
cursor.execute('SELECT email FROM accounts')
data2 = cursor.fetchall()
return render_template('profile2.html', data=data , data2=data2)
-----------------------------------------
Then I have this HTML template for the view(profile2)
{% extends 'layout.html' %}
{% block title %}Profile2{% endblock %}
{% block content %}
<h2>Profile Views</h2>
<div>
<p>Details are below:</p>
<table>
<tr>
<td>username</td>
<td>email </td>
</tr>
<tr>
<th>0 {{ data[0] }}</th>
<td>0 {{ data2[0] }} </td>
</tr>
<tr>
<th>1 {{ data[1] }}</th>
<td>1 {{ data2[1] }} </td>
</tr>
<tr>
<th>2 {{ data[2] }}</th>
<td>2 {{ data2[2] }} </td>
</tr>
<tr>
<th>3 {{ data[3] }}</th>
<td>3 {{ data2[3] }} </td>
</tr>
</table>
p
</div>
{% endblock %}
-------------------------
This app returns this
0 {'username': 'unu'} 0 {'email': '1@1.com'}
1 {'username': 'dos'} 1 {'email': 'two@two.com'}
2 {'username': 'test1'} 2 {'email': 'testtest@test.com'}
------------------
I want the HTML output to be this.
0 unu 1@1.com
1 dos two@two.com
2 test1 testtest@test.com