1

I have this class:

class View(object):
    def main_page(self, extra_placeholders = None):
        file = '/media/Shared/sites/www/subdomains/pypular/static/layout.tmpl'

        placeholders = { 'site_name' : 'pypular' } 

        # If we passed placeholders vars, append them
        if extra_placeholders  != None:
            for k, v in extra_placeholders.iteritems():
                placeholders[k] = v

My problem in the code above is the if statement

As you can see, the function takes an argument(extra_placeholders) which is a dict.

If i don't pass a parameter to main_page(),

if extra_placeholders  == None:
    return 'i executed'

runs fine. however,

if extra_placeholders  != None:
    return 'i cause error'

does not work. it causes a 500 internal server error. Why?

pnuts
  • 58,317
  • 11
  • 87
  • 139
sqram
  • 7,069
  • 8
  • 48
  • 66

1 Answers1

1

should you be using instead

if !( extra_placeholders  is  None) :

Edit: To reflect comment:

It appears (thanks) that you can also use:

 if extra_placeholders  is  not None :

Update: The orginal link is now dead so this SO answer is a good reference : https://stackoverflow.com/a/3289606/30225

Community
  • 1
  • 1
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • This is a good example why external links can be helpful, but the most relevant information should be copied into the answer... because the link is no longer available. – kmarsh Feb 24 '17 at 14:02