在HistoryPage posts = list(q)NameError:名称'q'未定义

时间:2013-09-03 12:34:32

标签: python python-2.7 nameerror

class HistoryPage(BlogHandler):
    def get(self, path):
        q = Page.by_path(path)
        q.fetch(limit = 100)

    posts = list(q)
    if posts:
        self.render("history.html" , path = path, posts = posts)

    else:
        self.redirect("/_edit" + path)

1 个答案:

答案 0 :(得分:0)

您有缩进错误。行posts = list(q)及其后的行应该进入get方法:

class HistoryPage(BlogHandler):
    def get(self, path):
        q = Page.by_path(path)
        q.fetch(limit = 100)

        posts = list(q)
        if posts:
            self.render("history.html" , path = path, posts = posts)   
        else:
            self.redirect("/_edit" + path)