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 How to Win Friends Follow and Unfollow Buttons

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

'method object' has no attribute 'count'

For some reason i get this error from jinja. Error appears while trying to render 'user_stream.html'.

Update:

everything works if i count followers and following outside the user_stream.html Example:

    def followers(self):
        """Users following me."""
        return (
            User.select().join(
                Relationship, on=Relationship.from_user
            ).where(
                Relationship.to_user == self
            )
        )

    def followers_num(self):
        return self.followers().count()

And then add it to user_stream.html :

        <div class="grid-33">
            <h5>Following</h5>
            <p>{{ user.following_num() }}</p>
        </div>

But it still doesn't work directly like in Kenneth's version:

        <div class="grid-33">
            <h5>Following</h5>
            <p>{{ user.following.count() }}</p>
        </div>

Update:

Works like:

        <div class="grid-33">
            <h5>Following</h5>
            <p>{{ user.following().count() }}</p>
        </div>

(with parentheses)

2 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hi Alexey. Can you please provide your code or part of it?