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 Django Basics Model Administration Adding Instances

def __str__(self): won't work

Now the str function won't run. I just typed: def str(self): return self.title within the scope of the class we built. I looked online and the only person I found with the same problem used 'unicode' to fix the issue. That is for python 2 though.

Could you post your code snippet?

Ensure you use the Markdown Cheatsheet when typing your answer, use the section that covers how to add Code

1 Answer

If you forgot to put dunders (two underscores __) around str, like this: str, then you should do that.

On the other hand, Python 2 is almost very different from Python 3. I would recommend Python 3 because Kenneth is using it and most of the other Treehouse students (including me) know Python 3 better than Python 2.

~Alex