ich eine Abfrage wie leite:MySQLdb Aufruf Typeerror: 'int' Objekt ist nicht iterable Python
SELECT post_title, post_name FROM wp_posts WHERE post_status='publish' ORDER BY RAND() LIMIT 3
die Informationen gibt wie:
ID post_title post_name
1 a title here a-title-here
2 a title here2 a-title-here2
3 a title here3 a-title-here3
und versuchen, es für Kolben in app.py
anrufen :
@app.route('/', methods=('GET', 'POST'))
def email():
blogposts = c.execute("SELECT post_title, post_name FROM wp_posts WHERE post_status='publish' ORDER BY RAND() LIMIT 3")
return render_template('index.html', form=form, blogposts=blogposts)
In meiner Vorlage, ich rufe blogposts
wie:
{% for blogpost in blogposts %}
<li><a href="{{blogpost[1]}}">{{blogpost[0]}}</a></li>
{% else %}
<li>no content...</li>
{% endfor %}
Aber Im erhalte eine Fehlermeldung aus:
{% for blogpost in blogposts %}
TypeError: 'int' object is not iterable
Was ich hier falsch mache?
wie bekommt man 'blogposts' in' E-Mail() '? es scheint, es ist eine Nummer, keine Liste oder Zeilen. – furas
Siehe oben. 'Blogposts 'ist buchstäblich eine Abfrage an mysql – Jshee
check' print (blogposts) 'in'E-Mail()', um zu sehen, was Sie bekommen. – furas