I can show the list of followers, but the button its not working(sorry for bothering,):
Views:
def userProfile(request, pk):
user = User.objects.get(id=pk)
profile = UserProfile.objects.get(user_id=pk)
rooms = user.room_set.all()#LOS ROOMS CREADOS
description = UserProfile.objects.get(user=user).description
#room_messages = user.message_set.all()#MENSAJES EN LOS ROOMS.
topics = Topic.objects.all()
if request.method == 'POST':
current_user_profile= request.user.userprofile
action = request.POST['follow']
if action == "unfollow":
current_user_profile.follows.remove(request.user.userprofile)
else:
current_user_profile.follows.add(request.user.userprofile)
current_user_profile.save()
context = {'user': user, 'profile':profile, 'rooms':rooms, 'description':description, 'topics':topics }#'room_messages':room_messages,
return render(request, 'base/profile.html', context)`
HTML:
<strong>Follows</strong>
{% for following in user.userprofile.follows.all %}
<p>@{{ following }} </p>
{% endfor %}
{% if profile in profile.follows.all %}
<button name="follow" value="unfollow" type="submit">
Unfollow @{{user.username}}
</button>
{% else %}
<button name="follow" value="follow" type="submit">
Follow @{{user.username}}
</button>
{% endif %}`