Reputation: 451
Could someone explain why friend = friend is necessarily in this flask function?
@app.route('/')
def index():
friends = mysql.fetch("SELECT * FROM friends")
return render_template('index.html', friends=friends)
Upvotes: 0
Views: 455
Reputation: 41
I think what you are asking is why do you have to say "friends = friends" instead of just passing "friends". Why the superfluous "friends"? The way to think about it is you are passing a keyword argument, which means defining a keyword and its value like so: "keyword = value". You might find this helpful from the Python docs.
Upvotes: 0
Reputation: 8011
In your template you have a variable called friends
. This code says use the friends results in the template as friends
.
Upvotes: 2
Reputation: 844
It's passing the friends list into the template so the data can be displayed.
Upvotes: 1