Issue
I don't know why I'm getting this error..
[ 'User' object is not iterable ]
here I want to print (logged in user) followers on the home page. apart from error is my models.py is right ? for followers and following mechanism.
model
class Follow(models.Model):
following = models.ForeignKey('auth.User', related_name='following')
followers = models.ForeignKey('auth.User', related_name='followers')
view
def profile(request):
current_user = request.user
twi = Follow.objects.get(pk=current_user.id)
display = twi.followers
return render(request,'home.html' ,
{'detail':display,'user':current_user,})
template
{% for o in detail %}
<h1>o.followers</h1>
{% endfor %}
Solution
You have a mixup in your logic, your detail
refers to followers
but the field itself is a link to a singular user, you either need to make this field a ManyToMany relationship, or use a reverse lookup to find what a user follows.
(Theres also a stray comma in your context dict which may cause issues later on..
Answered By - Sayse
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.