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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:50:43+00:00 2026-05-25T12:50:43+00:00

I have a few lines of code in my view that get a query

  • 0

I have a few lines of code in my view that get a query param and then filter based on that parameter.

search = request.GET.get('search', None)

if search:
    accounts = UserProfile.objects.filter(fullname__icontains=search).order_by('fullname')
else:
    accounts = UserProfile.objects.all().order_by('fullname')

For some odd reason, on my local machine, it appears that when I give a url of something like localhost/accounts/admin/ or localhost/accounts/admin/?search= it works fine — on my production server, however, it seems to think that the search is an empty string, and then it passes the if/then conditional which returns an empty queryset. GET:<QueryDict: {u'search': [u'']}>

Why does python seem to think that this empty string is “something?”

>>> x = ''
>>> if x:
...     print "Exists"
... else:
...     print "None"
... 
None

>>> x = u''
>>> if x:
...     print "exists"
... else:
...     print "None"
... 
None
  • 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-25T12:50:44+00:00Added an answer on May 25, 2026 at 12:50 pm

    Actually if you pay close attention the search variable is set to a list that contain an empty unicode string [u''] so that why it’s evaluated to True:

    >>> search = [u'']
    >>> bool(search)
    True
    

    And for why you are seeing different behavior between your test and production sadly i’m not sure why !? maybe the doc can help.

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

Sidebar

Related Questions

I have a few lines of PowerShell code that I would like to use
I have some repetitive code that is used by a few of my actions
I have a text file with a few 1000 lines of text in it.
I have a few links that should all open in the same window or
I have been trying to get a working algorithm that detects intersection between a
I want to add few lines of identical html code to several pages in
I have used a pattern of compound view models for a few of the
Some of my Javascript lines of code are longer than the editor window view.
Ok - I love NancyFx. Writing a web application with that few lines is
My application has a few portions that have really big buttons (640x130, 230x150, etc.)

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.