[Answered ]-How to redirect to another view with parameter in this example?

2👍

What about this:

def home(request):
    return render_intro(request)


@login_required
def share(request):
    return render_intro(request, is_share=True)


def render_intro(request, is_share=False):
    context = intro_context(request.user, is_share)
    return render(request, 'intro.html', context)


def intro_context(user, is_share=False):
    small = user.username.title()
    cases = Case.objects.filter(users=user).order_by('-english')
    groups = user.groups.all()
    allgroups = Group.objects.all()
    suggestgroups = set(allgroups).difference(set(groups))
    allusers = User.objects.all().exclude(username=user.username)

    if user.is_superuser:
        return {'suggestgroups': suggestgroups,
                'cases': cases,
                'groups': groups,
                'small' : small}

    user_ex = UserEx.objects.get(user=user)
    friendlist = FriendList.objects.get(user=user_ex)
    friends = friendlist.friends.all().exclude(username=user.username)
    friendrequest = FriendReqRecList.objects.get(user=user_ex)
    friendrequestsent = FriendReqSentList.objects.get(user=user_ex)
    friendrequests = friendrequest.friend_rec_requests.all().exclude(username=user.username)
    friendrequestsents = friendrequestsent.friend_sent_requests.all().exclude(username=user.username)
    nonfriends = set(allusers).difference(set(friends))

    context = {'allusers': allusers,
               'cases': cases,
               'friendrequests': friendrequests,
               'friendrequestsents': friendrequestsents,
               'friends': friends,
               'groups': groups,
               'nonfriends': nonfriends,
               'small' : small,
               'suggestgroups': suggestgroups}

    if is_share:
        sendgroups = groups
        sendfriends = friendlist.friends.all().exclude(username=user.username)
        context.update({'sendfriends': sendfriends,
                        'sendgroups': sendgroups})

    return context
👤lepsch

Leave a comment