Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8983909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:57:33+00:00 2026-06-15T20:57:33+00:00

Possible Duplicate: Django templates syntax error When i am using {% if request.user.is_authenticated %}

  • 0

Possible Duplicate:
Django templates syntax error

When i am using {% if request.user.is_authenticated %} condition for redirection on this code it throws error Invalid block tag: 'else'

{% if request.user.is_authenticated %}

{% extends "pages/page.html" %}
{% load mezzanine_tags shop_tags i18n %}
{% block body_id %}category{% endblock %}
{% block main %}{{ block.super }}
{% regroup products by category as products_by_category %}
{% for c in products_by_category %}
......  
         {% for p in c.list %}     
......
        {% if p.num_in_stock == None %}
...
         {% else %}
         {% if p.num_in_stock < 4 %}
...
            {% endif %}
            {% endif %}
        .....        
                   {% endfor %}
......
{% endfor %}
{% endblock %}

{% else %}

<script>
window.location="/stylequiz/";
</script>

If i am using this script then it gives no error

{% if request.user.is_authenticated %}
   <h1>welcome</h1>
{% else %}

<script>
window.location="/stylequiz/";
</script>
{% endif %}

I think there must be a problem with nested if .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:57:34+00:00Added an answer on June 15, 2026 at 8:57 pm

    You can’t put {%extends%} tag inside {%if%}. It should be first tag in the template.

    From django docs Template inheritance

    If you use {% extends %} in a template, it must be the first template tag in that template. Template inheritance won’t work, otherwise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Python-Django: ifchanged template tag This is my present code: {% for eachSc
Possible Duplicate: Django switching, for a block of code, switch the language so translations
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: Django Enter a list of values form error when rendering a ManyToManyField
Possible Duplicate: filter using Q object with dynamic from user? I am working on
Possible Duplicate: Understanding Python decorators I was reading a django app source code where
Possible Duplicate: How to put braces in django templates? When I use jQuery template
Possible Duplicate: django file upload from json Hi am using the following ajax upload
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.