1👍
✅
Make sure you’ve included the request context processor in your TEMPLATE_CONTEXT_PROCESSORS
setting, and that your view is rendered with a RequestContext
.
1👍
try with request = context.get('request', None)
if request key doesn’t exists assign None value.
http://docs.python.org/library/stdtypes.html#dict.get
Update:
Also you can pass user to inclusion_tag, with something like this
# In your template_tag
@register.inclusion_tag('template.html', takes_context=True)
def include_client_side_bar(context, user):
if user:
pass # do something
return {
'STATIC_URL': settings.STATIC_URL,
}
# in your template
{% include_client_side_bar user=request.user %}
- [Answered ]-Converting Django models queryset into a numpy matrix
- [Answered ]-Handling a conditional block in a custom Django template tag
Source:stackexchange.com