I’m getting the above error and I’ve tweaked my code based on answers I saw online but still getting the same error
VIEWS.PY
`
def profile(request, user_id):
profile_user = User.objects.get(pk = user_id)
# user_profile = Profile.objects.get(user=user_object)
profile_post = NewTweet.objects.filter(user = user_id)
post_count = len(profile_post)
follower = request.user.id
user = user_id
if Followers.objects.filter(follower=follower, user=user).first():
button_text = "Unfollow"
else:
button_text = "Follow"
context = {
"profile_user": profile_user,
"post_count": post_count,
"profile_post": profile_post,
"button_text": button_text,
}
return render(request, "network/profile.html", context)
`
URL.PY
path("profile/<int:user_id>", views.profile, name="profile"),
LAYOUT.HTML
`
<li class="nav-item">
<a class="nav-link" href="{% url 'profile' user.id %}">
<img src= {% static 'network/images/profile.svg' %} alt="Profile" class="left-sidebar-menu-icon">
Profile
</a>
<img src= {% static 'network/images/profile.svg' %} alt="Profile" class="left-sidebar-menu-icon">
Profile
</li>
`
MODELS.PY
class Profile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
id_user = models.IntegerField()
bio = models.TextField(blank=True)
def __str__(self):
return self.user.username
class Followers(models.Model):
follower = models.CharField(max_length=100)
user = models.CharField(max_length=100)
# follower = models.ForeignKey('User', on_delete=models.CASCADE, related_name='targets')
# target = models.ForeignKey('User', on_delete=models.CASCADE, related_name='followers')
def __str__(self):
return self.user
In Layout.html, I try ‘{{ user.id }}’ to see what is reflecting and it shows ‘None’.
I also adjusted this as adviced in a different thread but same error message
<a class="nav-link" href="{% url 'profile' user_id=user.id %}">
I expect that it would show me a button text of ‘Follow’ or 'Unfollow depending on if the user is currently following the current user
Please advise