python - IF 语句导致 webpy 出现内部服务器错误

标签 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),它是一个字典。

如果我不向 main_page() 传递参数,

if extra_placeholders  == None:
    return 'i executed'

运行良好。然而,

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

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

最佳答案

您是否应该使用

if !( extra_placeholders  is  None) :

编辑:反射(reflect)评论:

看来(谢谢)您还可以使用:

 if extra_placeholders  is  not None :

更新:原始链接现已失效,因此这个答案是一个很好的引用:https://stackoverflow.com/a/3289606/30225

关于python - IF 语句导致 webpy 出现内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1387902/

相关文章:

python - 什么是.so文件的库和包含目录变量?

python - 从 Python 中的字符串列表列表中获取连接字符串

Python:使用gevent,是否需要前端服务器/反向代理?

django - 使用 apache 和 mod_wsgi 时,我在哪里存储 django 项目代码?

python - 使用python web.py框架出错

python - SCRIPT_NAME 与 apache cgid 模块中的 web.py 不匹配 REQUEST_URI

python - 使用 web.py 如何在某人访问我的页面时获取他们的 IP

Python 使用 BinarySecurityToken 签署 SOAP 请求

python - 如何在 django-rest-framework 中通过关系使用 ManytoManyField

python - 带有 Python 3 的 wsgi 中的 openID