7
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..
2
get returns a single queryset and you cannot iterate over it, if you use get
use this in template
<h1>{{ detail.followers }}</h1>
or if you need multiple
in view
twi = Follow.objects.filter(pk=current_user.id)
and change this line
display = twi.followers
to
display = twi
and in template
{% for o in detail %}
<h1>{{ o.followers }}</h1>
{% endfor %}
- [Django]-Assigning a proxy model instance to foreign key
- [Django]-How start server Django in the VM (Vagrant)
- [Django]-Django: How is a RelatedManager object instantiated?
- [Django]-Django migration OperationalError: index [name] already exists
0
if you want to iterate over βdetailβ and do not want to change your code in the templates, use a filter() query and set 'display' to result of your filter query.
or if you are not planning to change your views code you can edit the template code from
{% for o in detail %}
<h1>o.followers</h1>
{% endfor %}
to just
<h1>{{detail}}</h1>
- [Django]-Extract values from Django <QuerySet> in Python 3
- [Django]-Python PIL β background displayed opaque instead of transparent