Skip to content Skip to sidebar Skip to footer

Create A Restricted Area

I'm trying to build a restricted area for a website in which only the registered user can see his personal profile and his posts. The staff users can see all users profile and rela

Solution 1:

I've solved is using this:

defuserProfile(request, username):
    if request.user.username == username:
        user_details = get_object_or_404(UserProfile, username=username)
    elif request.user.is_staff:
        user_details = get_object_or_404(UserProfile, username=username)
    else:
        raise PermissionDenied
    context = {
        "user_details": user_details,
        }
    template = 'usermanager/reading/user_profile.html'return render(request, template, context)

It is possible to use the same strategy for the others views.

Post a Comment for "Create A Restricted Area"