我在显示登录用户个人资料时遇到问题。我创建了一个配置文件应用程序,其中包含一些用户详细信
def profile_view(request):
user_id = request.user.user_id
profile = UserProfile.objects.get(user_id=user_id)
context = {'profile': profile}
template = 'profiles/profile.html'
return render(request, template, context)
答案 0 :(得分:3)
试试这个......
from django.contrib.auth.decorators import login_required
@login_required
def profile_view(request):
profile = UserProfile.objects.get(user=request.user)
context = {
'profile': profile
}
template = 'profiles/profile.html'
return render(request, template, context)