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 8789211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:20:30+00:00 2026-06-13T22:20:30+00:00

This seems like it should be pretty straightforward, but for some reason I am

  • 0

This seems like it should be pretty straightforward, but for some reason I am unable to solve this problem. I’m using Django 1.4. I am trying to do a basic check to see if a list QuerySet is empty or not during template rendering, but the if statement I’m using seems always to evaluate to true.

I have a Django template that reads:

{% extends 'includes/base.html' %}

{% if object_list %}
...
{% block data %}
   {% for object in object_list %}
     ...
     {{ object.create_date }}
     ...
   {% endfor %}
{% endblock data %}
...
{% endif %}

‘base.html’ has the block:

<body>
{% block content %}
  ...   
  <div class="row-fluid">
    <div class="span12">
      {% block data %}
      <div align="center"><i>No data.</i></div>
      {% endblock data %}
    </div><!-- span12 -->
  </div><!-- row -->
{% endblock content %}
...
</body>

The view function generating the QuerySet is here:

def barcode_track(request, model):
    query = request.GET.get('barcode_search', '')
    object_list = model.objects.all()
    if query:
        object_list = model.objects.filter(barcode__icontains=query)
    return render_to_response('barcode_track/barcode_list.html',
                              {'object_list': object_list, 'query': query},
                              context_instance=RequestContext(request))

Which is called via this form:

<form id="barcode_search_form" method="get" action="" class="form">
    <input type="text" name="barcode_search" value="{{ query }}" />
    <button type="submit" class="btn">Search</button>
</form>

And the urls.py line:

urlpatterns = patterns('barcode_track.views',
                       url(r'^$', 'barcode_track', {'model': Barcode},
                           name="barcode_track"),)

The idea is that results will only be presented if they exist in object_list, and otherwise the parent block will remain unaltered. I have tried changing the name of object_list, and I have printed {{ dicts }} to the page to ensure that object_list is, in fact, empty (which it is). I am not using a generic view, although I realize that the name suggests as much. I have actually had this trouble in a different app I wrote using similar logic, so I must be doing something systematically incorrectly.

What am I missing here?

  • 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-13T22:20:31+00:00Added an answer on June 13, 2026 at 10:20 pm

    You can’t wrap control flow tags like if around a block. Your problem is that the child template’s definition for block data is being used simply because it’s there.

    You can fix it by placing the if tag inside block data. If you want to inherit the parent’s contents when the list is empty, add an else case that expands to {{ block.super }}.

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

Sidebar

Related Questions

This one seems like it should be pretty straightforward, but I couldn't quite figure
This seems like it should be pretty straight forward, but I'm apparently confused. I
This feels like it should be pretty simple, but not much seems to be
This seems like it should be really simple, but I'm unable to figure this
This seems like a pretty basic thing to do but although I've been using
This seems like it should be pretty obvious, but I've tried substitute , bquote
This seems like it should be relatively straightforward, I cannot figure out what I'm
This seems like it should be easy, but I can't quite find an explanation
This seems like it should be obvious but I can't figure it out. Suppose
This seems like it should be something very easy to do, but every time

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.