1
votes

I'm working through the Flask Mega Tutorial by Miguel Grinberg and I have an odd issue that I can't seen to figure out.

The blog is set up so you can have other users as followers. The /index page is supposed to list blog posts from your followers. You are supposed to be your own follower, so your blog posts should show up in /index and /user. My posts only show up in the /user page.

My repository of what I have already is here:

https://github.com/asdoylejr/microblog

From what I can tell everything I've done so far is line-for-line from the tutorial. I'm not sure why my test posts are listed in the /user view but not /index.

In the /index view, posts is defined as:

posts = g.user.followed_posts().paginate(page, POSTS_PER_PAGE, False)

But in the /user view, it's defined as:

posts = user.posts.paginate(page, POSTS_PER_PAGE, False)

If I change the /index posts variable to match /user, it returns an error.

Can anyone help me spot what I'm missing?

Thanks

1

1 Answers

2
votes

To check if the user is following him/herself you can try the following in a Python shell:

>>> from app import models
>>> u = models.User.query.filter_by(email = '<user-email-here>').first()
>>> u.is_following(u)
True

If you get False, then for some reason the relationship was not setup. You can fix it with:

>>> from app import db
>>> u.follow(u)
>>> db.session.add(u)
>>> db.session.commit()

If this fixes it, then the problem was in the database. Maybe the user you are testing this with was created before you added the followers feature to your copy of the project.