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

  • SEARCH
  • Home
  • 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 7992887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:41:58+00:00 2026-06-04T13:41:58+00:00

Just learning Django, and I’m trying to create a situation where when a template

  • 0

Just learning Django, and I’m trying to create a situation where when a template has layouts it’ll list them, but if it doesn’t it won’t and will instead state that there are none.

I got an error message when I used only a “for layout…” statement on templates that had no layouts.

I figured things out to the point that I created an “if” statement to first check and see if the pages had layouts, and if not, an “else” statement to say that there are none.

The end result, though, is that the “for” seems to be completely ignored, and the “else” condition is applied on all pages — whether or not they have associated layouts.

Code:

{% block header %}
    <h1>The name of this template? It's {{ boilerplate.name }}.</h1>
{% endblock %}

{% block content %}
    <p>&nbsp;</p>
    <p>{{ boilerplate.content }}</p>
    {% if layout in boilerplate.layouts %}
        {% for layout in boilerplate.layouts.all %}
        <p><a href="{{ layout.file.url }}">{{ layout.user }} -- {{ layout.name }} ({{ layout.file.size }})</a>
        {% endfor %}
    {% else %}
    <p>There are no layouts for this template.</p>
    {% endif %}
{% endblock %}

There’s obviously something I’m missing. Possibly something very simple. What am I dong wrong?

  • 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-04T13:42:00+00:00Added an answer on June 4, 2026 at 1:42 pm

    Your {% if layout in boilerplate.layouts %} is what’s wrong, but there’s an easier way to achieve this than using an additional if tag.

    As the documentation shows, you can use an optional empty tag to handle situations when you have no layouts. Rewriting your example code:

        {% for layout in boilerplate.layouts.all %}
        <p><a href="{{ layout.file.url }}">{{ layout.user }} -- {{ layout.name }} ({{ layout.file.size }})</a>
        {% empty %}
        <p>There are no layouts for this template.</p>
        {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just learning django's templating system and trying to do something relatively trivial: <h2>State</h2>
I'm learning Python and django at the same time. I'm trying to create an
I'm just learning Django, and I'm trying to set up the admin area for
I'm just learning Django and trying to setup the View and URLconfs ( http://djangobook.com/en/2.0/chapter03/
So I have just begun learning the Django framework, and I am trying to
Just learning Automator here, but I'm trying to run a convert command on a
Im just learning mod_rewrite and regex stuff, and what I'm trying to do is
I'm just learning django and following a tutorial. I have a Link and a
Learning django & python. Just set up a new site after doing the tutorial.
I'm just learning about SproutCore now, seems great. But I can't find a good

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.