IF statement causing internal server error with webpy

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?


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

链接地址: http://www.djcxy.com/p/76628.html

上一篇: 用于确定NaN或Null的定义函数不起作用

下一篇: IF语句导致webpy发生内部服务器错误