[Answered ]-Django link to a specific users profile page

1👍

Add a variable to your view:

def view_profile(request, account):
    ...

And urls:

path('view_profile/<str:account>', ...)

Then you can go to url: localhost:8000/view_profile/logan9997.

You can do it better with User id:

path('view_profile/<int:pk>', ...)

def view_profile(request, pk):
    account = User.objects.get(id=pk).username
    ...

And go for: localhost:8000/view_profile/1

This is very not Django-style:

posts = [post for post in Posts.objects.all()
if post.user_id.username == account]

Use filter() method instead:

posts = Posts.objects.filter(user_id__username=account)
# and
followers = Relationships.objects.filter(acc_followed_id__username=account)

Leave a comment