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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:54:04+00:00 2026-06-17T00:54:04+00:00

Pretty much a newbie when it comes to both Django and Python. Would appreciate

  • 0

Pretty much a newbie when it comes to both Django and Python. Would appreciate some suggestions here. I did search for similar questions, but couldn’t find one that solved my problem.

This is a view that I have written. The intended behaviour is to check the length of a list (districts list), and render to one template if there is only one object in that list, and to another if there are more than one. If there are no objects in the list, 404 is automatically raised.

    @never_cache
def district_list(request, county_slug):
    districts_list = get_list_or_404(NeigbourhoodPostcodeDistrict, county__slug=county_slug)
    if districts_list.count() == 1:
        context = {
        'districts_list': districts_list,
        }
        return render_to_response('neighbourhood/neighbourhood.html',context,context_instance=RequestContext(request))
    else:
        context = {
            'districts_list': districts_list,
        }
        return render_to_response('neighbourhood/district-list.html',context,context_instance=RequestContext(request))

Any help would be much appreciated

  • 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-17T00:54:05+00:00Added an answer on June 17, 2026 at 12:54 am

    You are looking for the len() builtin.

    E.g:

    if len(districts_list) == 1:
        ...
    

    The seq.count() method counts the number of times an individual element occurs in the sequence, and requires one argument (the element to count).

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

Sidebar

Related Questions

I'm a total newbie when it comes to CSS so I've pretty much given
Pretty much a complete Linux/Apache newbie here, I am in the process of moving
Would appreciate any help to a newbie here. I have a simple if/else if
I am a pretty much a newbie to Entity Framework (specifically version 4) and
I'm pretty much a complete newbie to PHP. My background is C/C++ and C#.
I'm pretty much a newbie and I need to dig into this matter to
I am pretty much a newbie to objective-c and as I started to program,
I want to create a ribbon-based GUI. I am pretty much a newbie when
Pretty much every product I've worked on over the years has involved some level
Pretty much forgot how to code C++ at all. Anyway, here is the problem.

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.