Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Build a Social Network with Flask Broadcasting Stream Views

g.user vs. current_user

What is the difference between the two and when should each be used? Thanks!

John

2 Answers

g.user is used to make the a variable global so it can be accessed in any scope where current_user is a object which tells us current active user, we use g.user to make the current_user object global so it can be used anywhere ...

Hope that helps

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Great answer with one minor nitpick. g can be accessed in any view, not any scope. You can't, for instance, use g in your models without some juggling.

nuri jeon
nuri jeon
14,376 Points

I still am not quite sure about this part. So when we use the post view, we need global object but when we use stream view, we don't need it to be global? Please somebody help @@ I don't understand when to use g.user and when to use current_user stilllll Thank you X(