IF语句导致webpy内部服务器错误
我有一个这样的类:
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),它是一个字典。
如果我不传参数给main_page(),
if extra_placeholders == None:
return 'i executed'
代码运行得很好。但是,
if extra_placeholders != None:
return 'i cause error'
这样做就不行了,导致出现500内部服务器错误。为什么会这样呢?
1 个回答
1
你应该使用这个吗?
if !( extra_placeholders is None) :
编辑:根据评论更新:
看起来(谢谢)你也可以使用:
if extra_placeholders is not None :
更新:原来的链接现在已经失效,所以这个StackOverflow的回答是个不错的参考: https://stackoverflow.com/a/3289606/30225