Answer the question
In order to leave comments, you need to log in
How to fix problem getting user id in Django?
Django replaces the user id with the id of the logged in user.
path('profile/<pk>/', UserProfile.as_view(), name = 'profile_url'),
class UserProfile(View):
def get(self, request, pk):
user = User.objects.get(pk = pk)
username = user.username
name = user.first_name
surname = user.last_name
last_online = user.last_login
categories = Category.objects.all()
return render(request, 'profile.html', {'user': user,
'username': username,
'name': name,
'surname': surname,
'last_online': last_online,
'categories': categories})
<a class="nav-link" href="{% url 'profile_url' pk=user.id %}">Профиль</a>
Answer the question
In order to leave comments, you need to log in
The context processor django.contrib.auth.context_processors.auth
overrides your context variable with user
its own. Rename it to something else.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question