I'm new to Django and I'm trying to display each user's profile. So far, I've made a sign-in, sign-up system. User can also update their profiles but I'm really not able to show each user's profile as soon as the logged in user clicks on the other user's username. I was wondering if I could do something with the primary key/ID of the each profile and use it to get access to every profile. A little help would be really appreciated!
Here's what my code looks like:
The URL to the Profile's page:
path('profile/', views.userprofile, name='userprofile'),
My view to view the profile:
@login_required
def userprofile(request):
Post = post.objects.order_by('-created')
return render(request,'social_media/profile.html', {'Post':Post,'Profile':Profile})
Model for user's profile:
class profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
desc = models.CharField(max_length=1000)
pfp = models.FileField(default='images/profile.jpg', upload_to='profile_pics/', blank=True)
cover = models.FileField(default='images/profile.jpg', upload_to='cover_pics/', blank=True)
Link that take me to the profile URL:
<div class="user-pfp-name">
<a href="{% url 'userprofile' %}">
<img src="{% static 'social_media/images/profile.jpg' %}" style="height: 35px; width: auto; border-radius: 100%;" alt="">
{{ i.user.first_name }}
{{ i.user.last_name }}
</a>
</div>
and lastly here's my profile page:
<div class="profile">
<div class="coverpad">
{% if Profile.cover %}
<img src="{{ Profile.cover.url }}">
{% endif %}
</div>
<div class="profilepic">
{% if Profile.pfp %}
<img src="{{ Profile.pfp.url }}" height="140px">
{% endif %}
</div>
<div class="profile-middle">
<div class="profile-username">{{ user.first_name }} {{ user.last_name }}</div>
{% if Profile.desc %}
<div class="profile-desc"></div>
{% endif %}
</div>
</div>