Opened 12 years ago

Closed 12 years ago

#20219 closed Bug (wontfix)

block evaluation preceeds if-statement evaluation

Reported by: djangobug@… Owned by: nobody
Component: Template system Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a login page on my website that extends the base template. I a user is already logged in and visits the login page again, I want to show a notice saying that the user is already logged in.

The base.html template contains a

{%block meta%}{%endblock%}

placeholder in the head of the html document.

In the login page I added:

{%extends "base.html"%}
{%if user and user.is_authenticated%}
  {%block meta%}
    <meta http-equiv="refresh" content="0;url=/">
  {%endblock%}

  {%block content%}
  You are already logged in, etc.
  {%endblock%}
{%else%}
  show the login form, etc
{%endif%}

The problem is that even when I'm not logged in, the meta-tag is still inserted in the html page. This causes the login form to be refreshed continuously, making it impossible to log in.

I have found a workaround: In the base template I placed an is_authenticated check around the meta block:

{%if user.is_authenticated%}
  {%block meta%}{%endblock%}
{%else%}
  {%block meta_unauth%}{%endblock%}
{%endif%}

This prevents the meta-tag from being placed on the page when the user is not authenticated (the meta block does not exist then).

It seems to me that the evaluation of the block- and if-statements is not in the correct order in the template, but it is in the correct order in the base.html template.

Change History (1)

comment:1 by Aymeric Augustin, 12 years ago

Resolution: wontfix
Status: newclosed

Conditionally overriding blocks isn't allowed (see previous tickets on this matter).

Note: See TracTickets for help on using tickets.
Back to Top