[Answered ]-How to pass argument on custom context_processors.py?

2👍

Context processors are fairly simple, with only 1 argument; HttpRequest

What you could do, is add something to the session because that would be accessible via the request, but unless it’s something system wide or quite generic then you are often better off providing your context variables via your views. Specifically in your example, if you’re providing a username in an URL, you are providing a context in the response of that view, so you could simply provide the client at that point.

Anyway, if you provided something through the session your code might look like;

def client_profile(request, username):
     # .... some context
     request.session['username'] = username
     return render_to_response(
         'profile.html', context, 
         context_instance=RequestContext(request, username)
     )

def default_profile(request):
    context = {}
    if 'username' in request.session:
        username = request.session['username']
        client = get_object_or_404(Client, user__username=username)
        context.update({
            'client': client,
        })

    return context

Leave a comment