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 Takin' Names LoginManager

The comma in order_by = ('joined_at',)

Hi everyone,

So after this video, I decided to run my app.py just to make sure the tables and user was being created and there were no bugs.

After I cleared up the inevitable typos I kept getting KeyErrors.

I checked and double checked my code but couldn't work out why an error was being throw. Thankfully a quick google lead me to the comma missing from ('joined_at',).

What's the deal? Why does that throw a KeyError?

Thanks guys,

Tayler

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

It is context specific, but some objects want a container of things instead of a single object. Many times a tuple is used as the preferred container. In the case of passing a single item in a container, a comma is needed to indicate the parens represent a container and not just grouped code, for example a line continuation.

Hi Chris, thanks for getting back to me.

I think I understand. So Flask is looking for a container with 2+ items, and when it can only find one it throws an error, so adding a comma sort of tricks it into thinking there's another item there.

It's seems confusing in this case seeing as you can surely only "order_by" one thing!