使用webpy导致内部服务器错误的IF语句

时间:2009-09-07 06:54:40

标签: python mod-wsgi web.py

我有这堂课:

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

上面代码中的问题是if语句

如您所见,该函数接受一个参数(extra_placeholders),这是一个dict。

如果我没有将参数传递给main_page(),

if extra_placeholders  == None:
    return 'i executed'

运行正常。然而,

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

不起作用。它会导致500内部服务器错误。为什么呢?

1 个答案:

答案 0 :(得分:1)

你应该使用

吗?
if !( extra_placeholders  is  None) :

编辑:反映评论:

看来(谢谢)你也可以使用:

 if extra_placeholders  is  not None :

更新:原始链接现在已经死了所以这个SO答案是一个很好的参考:https://stackoverflow.com/a/3289606/30225

相关问题