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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:25:48+00:00 2026-05-23T04:25:48+00:00

I was working from an example of an ‘if’ statement, but for some reason

  • 0

I was working from an example of an ‘if’ statement, but for some reason I cannot get it to work.
I tried every possible statement in the ‘if’, but it seems as though nothing makes it true for the if statement to run. Instead the Else statement runs.

Sample

{% extends 'base.html' %}
{% block content %}

<h2>Hardware Inventory</h2>

{% if hardware %}

<table id="datatable">
    <thead>
        <tr>
            <th>Name</th>
            <th>Manufacturer</th>
            <th>Category</th>
        </tr>
    </thead>
    <tbody>
    {% for item in hardware %}
        <tr>
            <td><a href="/inventory/hardware/{{ item.id }}">{{ item.name }}</a></td>
            <td>{{ item.manufacturer }}</td>
            <td>{{ item.kind }}</td>
        </tr>
    {% endfor %}
    </tbody>
</table>

{% else %}

<p>The inventory is empty.</p>

{% endif %}


{% endblock %}

Mine

{% extends 'base.html' %}
{% block content %}

<h2>News</h2>

{% if entry %}

{% for item in entry %}
<table id = "news">
    <tr>
        <td><a href="/news/Entry/{{ item.id }}">{{ item.title }}</a></td>
        <td>{{ item.body }}</td>
        <td>{{ item.pub_date }}</td>
    </tr>
</table>
{% endfor %}



{% else %}
<p>No News</p>
{% endif %}


{% endblock %}

My view.py for news, Im not sure how to write it correctly, but i tried different combinations, this one errors at the moment causes it to crash

def index(request):
    return render_to_response('news/index.html', {'Entry': Entry}, context_instance=RequestContext(request))

def Entry(request):
    Entry = Entry.objects.all().order_by('pub_date')
    return render_to_response('news/Entry.html', {'item':item}, context_instance=RequestContext(request))
  • 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-05-23T04:25:48+00:00Added an answer on May 23, 2026 at 4:25 am

    Make sure you’re actually passing entry into the context. For example:

    render_to_response('template.html', { 'entry': entry })
    

    Unset variables behave as variables set to None in Django templates.

    UPDATE:

    Made some revisions to your view code; not even sure how you got to the template rendering with what you had.

    Original:

    def index(request):
        return render_to_response('news/index.html', {'Entry': Entry}, context_instance=RequestContext(request))
    
    def Entry(request):
        Entry = Entry.objects.all().order_by('pub_date')
        return render_to_response('news/Entry.html', {'item':item}, context_instance=RequestContext(request))
    

    Modified:

    def index(request):
        entry = Entry.objects.all().order_by('pub_date')
        return render_to_response('news/index.html', {'entry': entry}, context_instance=RequestContext(request))
    

    I don’t think you even needed the Entry method, so removed that. I kept your naming the same, but it’s better form to call that variable entries since it’s multiple items.

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

Sidebar

Related Questions

I am trying to get some code working from an example I came across.
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I am trying to get a simple example working from an assembly book I
I am working from this example: http://jqueryui.com/demos/tabs/ and trying to get the tabs to
I am working on an example from a php book and am getting an
I'm working for the first time with Forms Authentication, I'm using an example from
I am working on getting parameter from a function string. For example, my function
I have not done much database programming at all. I am working from some
I have everything working from the tutorial, replacing it with my data, but it
I'm working from an example piece of code that allocates a relatively large local

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.