I am new to Python flask and would like to put the results of a loop in a variable but is seems out of scope.
How can i get this to the parent scope, the view scope, in snippet below?
@users.route('/list', methods=['GET'])
@login_required
users = User.query.all()
link_count = {}
for user in users:
link_count = Link.query.filter(Link.user_id == user.id).count()
flash(f'{link_count}') # works and gives me a list/ array
flash(f'{link_count}') # null
return render_template('user_stats.html', title='Users', users=users)