在django中访问其他用户的信息
我知道要访问登录用户的数据,我们使用request.user。我的目标是列出表中的所有用户,并有一个指向其个人资料页面的链接。如何使链接转到用户的配置文件页面 我有以下资料:在django中访问其他用户的信息,django,Django,我知道要访问登录用户的数据,我们使用request.user。我的目标是列出表中的所有用户,并有一个指向其个人资料页面的链接。如何使链接转到用户的配置文件页面 我有以下资料: # app/views.py def tutors_list(request): user_list = CustomUser.objects.all() context = { 'user_list': user_list } return render(request, 'tutors_li
# app/views.py
def tutors_list(request):
user_list = CustomUser.objects.all()
context = {
'user_list': user_list
}
return render(request, 'tutors_list.html', context)
def show_profile(request, username):
user = CustomUser.objects.get(username = username) ### NOT DISPLAYING RIGHT USER
#user = CustomUser.objects.get(id=id)
context = {
'user': user
}
return render(request, 'show_profile.html', context)
# myproject/urls.py
url_patterns = [
# ...
path('show_profile/', views.show_profile, name='show_profile'),
# ...
我收到一个错误,表示show_profile需要1个参数username。如果我需要为数据库中的特定用户而不是登录用户提取数据,那么该模型的具体工作原理是什么?正如您的错误所述,show\u profile还需要一个参数username,因此您需要在url模式中传递username:
path('<str:username>/show_profile/', views.show_profile, name='show_profile'),