简体   繁体   中英

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

#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>
<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>

< main .Modeldb object at 0xb5db0c8c>

< main .Modeldb object at 0xb5db0c0c>

< main .Modeldb object at 0xb5db0ccc>

< main .Modeldb object at 0xb5db0d0c>

< main .Modeldb object at 0xb5db0d4c>

< main .Modeldb object at 0xb5db0d8c>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM