渲染模板烧瓶数据不显示

时间:2018-03-12 15:42:55

标签: python sqlite templates flask

我有这样的功能

def main():
    ''' Demonstrate UDF '''
    with sqlite3.connect("User.db") as conn:
        conn.row_factory = dict_factory
        conn.create_function("date_parse", 1, date_parse)
        cur = conn.cursor()
        rows  =  cur.execute("SELECT Status,date_parse(DateEntered) as 'DateEntered', EnteredBy, DateModified, AccountName,SalesRepName FROM data WHERE Status!=''and EnteredBy!=''  order by DateEntered asc ").fetchall()

def date_parse(s):
    ''' Converts a string to a date '''
    try:
        t = parser.parse(s, parser.parserinfo(dayfirst=True))
        return t.strftime('%Y/%m/%d %H:%M')
    except:
        return None

def dict_factory(cursor, row):
    ''' Helper for dict row results '''
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d

当我使用

for row in rows:
    print (row)

我得到我需要的所有数据,以正确的方式订购,当我想在我的网络应用程序上显示它时购买,我得到例外

@app.route('/Accont/')

def SetUp():
    # ...code 
    return render_template('navbar.html',rows = rows)

我试图直接从jinga2渲染模板而没有请求,但这对我没有帮助。有人可以帮我在我的网络应用程序上以正确的顺序显示数据吗?

Navbar.html

    <thead>
      <tr>
        <th>Status</th>
        <th>DateEntered</th>
        <th>EnteredBy</th>
        <th>DateModified</th>
        <th>AccountName</th>
        <th>SalesRepName</th>




              </thead>
              <tbody>


                {% for row in rows %}

                <td>{{row[0]}}</td>
                <td>{{row[1]}}</td>
                <td>{{row[2]}}</td>
                <td>{{row[3]}}</td>
                <td>{{row[4]}}</td>
                <td>{{row[5]}}</td>

          {%endfor%}

收到此错误:sqlite3.OperationalError:用户定义函数引发异常

0 个答案:

没有答案