簡體   English   中英

IF語句導致Webpy內部服務器錯誤

[英]IF statement causing internal server error with 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內部服務器錯誤。 為什么?

您應該使用代替

if !( extra_placeholders  is  None) :

編輯:反映評論:

似乎(感謝)您也可以使用:

 if extra_placeholders  is  not None :

更新:原始鏈接現在已死,因此此SO答案是一個很好的參考: https : //stackoverflow.com/a/3289606/30225

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM