Pergunta

I am using Django flatpages and would like to implement some logic in a template based on a user session variable.

eg.

{% if session.my_var %}
    YES
{% else %}
    NO
{% endif %}

Problem is that session object is not defined in flatpage context.

Foi útil?

Solução

Create a TEMPLATE_CONTEXT_PROCESSOR which is then used by the RequestContext (see docs).

def session(request):
    return { 'session': request.session }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top