python - Sqlalchemy: Purpose of .all() -


this question has answer here:

what use of .all(). when following function

def showrestaurants(): restaurants = session.query(restaurant) return render_template('restaurant.html',restaurants=restaurants) 

returns same result function

def showrestaurants(): restaurants = session.query(restaurant).all() return render_template('restaurant.html',restaurants=restaurants) 

for restaurant.html file

<html> <body> <h1> restaurants </h1>  {% x in restaurants %} </br>  {% endfor %} </body> </html> 

first example returns query object , can apply additional methods on it, such all() - return results represented query list.

query object works on each row before give it, while second works on rows, before starting give them.


Comments

Popular posts from this blog

Receive udp packets in android gstreamer -

php - Extract Text from HTTP referer -

java - Callback from new thread to class from which thread was initiated -