python - Passing variables to templates in Django -
python - Passing variables to templates in Django -
i have seen similar questions , answers none address problem.
i want view perform user grouping check , pass via variable template. template utilize appear differently different user groups.
my views.py:
def cans(request): is_canner = request.user.groups.filter(name='canner') #check if user grouping = canner can_list = can.objects.order_by('name') context = {'can_list': can_list} homecoming render(request, 'cans/cans.html', context) #need homecoming is_canner variable here
and in template utilize variable so:
{% if is_canner %} canner stuff goes here {% endif %}
i'm unsure how pass variable, thought used context send so:
return render(request, 'cans/cans.html', context({"is_canner": is_canner}))
but gives me errors - context not callable.
context not function, argument render function, e.g.
context = {"is_canner": is_canner} homecoming render(request, 'cans/cans.html', context)
docs: https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render
more background info: django - difference between render(), render_to_response() , direct_to_template()?
python html django templates
Comments
Post a Comment