質問

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.

役に立ちましたか?

解決

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

def session(request):
    return { 'session': request.session }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top