TypeError при рендеринге страницы
Я не понимаю, почему он продолжает говорить, что объект int не является итерируемым. помогите, ребята?
Я пытаюсь:
- get the list of users that are following us
- initialize an empty posts list and set qs equal to none
- loop through the users list 3A) for each user that we are following - grab it's profile 3B) for every profile that we know have - grab the posts 3C) add the posts to the post list
- grab our posts
- if posts list isn't empty sort the posts by created date
Error during template rendering
In template C:\Users\Khaled\Desktop\social\project4\network\templates\network\profile_test.html, error at line 12
'int' object is not iterable
2
3 {% block title %}
4 Profiles
5 {% endblock title %}
6
7 {% block body %}
8 <p><b>My Posts: </b> {{profile.get_my_posts}}</p>
9 <p><b>My Posts number: </b> {{profile.get_num_posts}}</p>
10 <p><b>Following Profiles: </b> {{profile.get_following}}</p>
11 <p><b>Following Profiles List: </b> {{profile.get_following_users}}</p>
12 <p><b>My Posts and Posts of Following Users: </b> {{profile.get_all_posts}}</p>
13 {% endblock %}
14
def get_all_posts(self):
users = [user for user in self.get_following()]
posts = [0]
qs = None
for u in users:
p = Profile.objects.get(user=u)
p_posts = p.post_set.all()
posts.append(p_posts)
my_posts = self.post_set.all()
posts.append(my_posts)
if len(posts) > 0:
qs = sorted(chain(*posts), reverse=True, key=lambda obj: obj.created)
return qs