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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -