Django custom proxy for fast access

I have a proxy model for the user:

class MyUser(User):
    class Meta:
        proxy = True

How can I get it in templates without going from view? can i only get it from request.user instance?

I use a template context handler for this:

def m_processor(request):
    from main.models import MyUser
    mu = MyUser.objects.get(id = request.user.id)
    return {'meuser':mu}

TEMPLATE_CONTEXT_PROCESSORS = (
    'settings.m_processor',
    )

Best exsists solution?

+3
source share
1 answer

In your view, when you return render_to_response, you can add context_instance = RequestContext (request).

return render_to_response("template_name", "vars_dict", context_instance = RequestContext(request))

This will make the variable request accessible from the template.

+1
source

Source: https://habr.com/ru/post/1758467/


All Articles