簡體   English   中英

如何使用flask_sqlalchemy在html上打印sqlite3的結果

[英]how to print results of sqlite3 on html using flask_sqlalchemy

大家好,開發人員。 我已經搜尋了幾個小時並閱讀了一段時間的文檔,但是我似乎無法將allmodels的內容打印到html文件中

#python file
@app.route('/models')
#@login_required
def models(): 
    allmodels = Modeldb.query.all() #THIS RETURNS A LIST FORM SQLITE3
    return render_template('models.html', allmodels=allmodels)

這是HTML文件

<html>
<head>

<body class = "body">

<body>
<h1> HELLOO </h1>


{% for models in allmodels %}
<p> {{ models }} </p>
{% endfor %}


</body>

</head>
</html>

它輸出

HELLOO <位於0xb5db0bcc的主要 .Modeldb對象>

<位於0xb5db0c8c的主要 .Modeldb對象>

<位於0xb5db0c0c的主要 .Modeldb對象>

<位於0xb5db0ccc的主要 .Modeldb對象>

<位於0xb5db0d0c的主要 .Modeldb對象>

<位於0xb5db0d4c的主要 .Modeldb對象>

<位於0xb5db0d8c的主要 .Modeldb對象>

我知道我親密。 或者可能不是。 :)在此先感謝你們,更多的精力給你們;))))

好的。 所以我想通了。

 {% for models in allmodels %}
 {{row["column_name_here"]}} 
 {{row["another_column_name_here_if_u_want"]}} 
 {% endfor %}

這基本上可以做到。 :)

恭喜你弄明白了 :)。 還無法發表評論,因此請使用其他語法添加此帖子:

{% for models in allmodels %}
    {{models.column_name_here}} 
    {{models.column2_name_here}} 
{% endfor %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM