Rory Perro
Rory Perro

Reputation: 451

python flask render_template

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

Answers (3)

robertkohl125
robertkohl125

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

Jerome Anthony
Jerome Anthony

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

mindcruzer
mindcruzer

Reputation: 844

It's passing the friends list into the template so the data can be displayed.

Upvotes: 1

Related Questions