Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在呈现模板中正确地将mysql查询结果返回或显示为html的多行_Python_Html_Mysql_Flask_Mysql Workbench - Fatal编程技术网

Python 如何在呈现模板中正确地将mysql查询结果返回或显示为html的多行

Python 如何在呈现模板中正确地将mysql查询结果返回或显示为html的多行,python,html,mysql,flask,mysql-workbench,Python,Html,Mysql,Flask,Mysql Workbench,我对这条蟒蛇和烧瓶还不熟悉 我的问题是如何从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.c

我对这条蟒蛇和烧瓶还不熟悉

我的问题是如何从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炼金术。我所要做的就是干净地返回它,而不使用大括号和列名

我的main.py上有这个代码

@应用程序路径“/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


甚至我也有同样的疑问。试试@foreach


我用了同样的方法,结果就像你想要的那样

甚至我也有同样的疑问。试试@foreach

我用了同样的方法,结果就像你想要的那样

@foreach ($items as $item)
<div class="col-md-2" >
 <h4 class=""> {{ $item -> name }}</h4>
  <div class="action-wrap">
    <div class="price-wrap h5 text-center">
      <span class="price-new"><b> ${{ $item->price }} </b></span>
    </div>
   </div>           
</div>
@endforeach