简体   繁体   English

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

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

Good Day fellow developers. 大家好,开发人员。 I have been googling for hours and reading documents for a while but i cant seem to print the contents of allmodels into the html file 我已经搜寻了几个小时并阅读了一段时间的文档,但是我似乎无法将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)

here is the html file 这是HTML文件

<html>
<head>

<body class = "body">

<body>
<h1> HELLOO </h1>


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


</body>

</head>
</html>

and it outputs 它输出

HELLOO < main .Modeldb object at 0xb5db0bcc> HELLOO <位于0xb5db0bcc的主要 .Modeldb对象>

< main .Modeldb object at 0xb5db0c8c> <位于0xb5db0c8c的主要 .Modeldb对象>

< main .Modeldb object at 0xb5db0c0c> <位于0xb5db0c0c的主要 .Modeldb对象>

< main .Modeldb object at 0xb5db0ccc> <位于0xb5db0ccc的主要 .Modeldb对象>

< main .Modeldb object at 0xb5db0d0c> <位于0xb5db0d0c的主要 .Modeldb对象>

< main .Modeldb object at 0xb5db0d4c> <位于0xb5db0d4c的主要 .Modeldb对象>

< main .Modeldb object at 0xb5db0d8c> <位于0xb5db0d8c的主要 .Modeldb对象>

I know im close. 我知道我亲密。 or maybe not. 或者可能不是。 :) thanks in advance and more energy to you guys ;)))) :)在此先感谢你们,更多的精力给你们;))))

okay. 好的。 soo i figured it out. 所以我想通了。

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

this basically did the thing. 这基本上可以做到。 :) :)

Glad you figured it out :). 恭喜你弄明白了 :)。 Not able to comment yet, so adding this post with alternative syntax: 还无法发表评论,因此请使用其他语法添加此帖子:

{% 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