在V2EX中新建一个页面就报错了 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
paloalto
V2EX    V2EX

在V2EX中新建一个页面就报错了

  •  
  •   paloalto 2010-11-17 13:00:21 +08:00 4799 次点击
    这是一个创建于 5471 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想新加一个功能,就是一个静态的图片展示html页面,但是对模板不太了解,所以拷贝images.py新建了一个explore.py,修改了class ImagesHandler为class ExploreHandler,对应的path也改成了desktop下的explore.html文件。

    另外,app.yaml里也加上了
    - url: /explore
    script: explore.py

    但是访问http://xxxxx/explore怎么还是报错呢?主要报错信息:
    File "/Users/hanjiyun/GAE-11-14/geekiwi/explore.py", line 36, in <module>
    class ExploreHandler(webapp.RequestHandler):
    File "/Users/hanjiyun/GAE-11-14/geekiwi/explore.py", line 39, in ExploreHandler
    browser = detect(self.request)
    NameError: name 'self' is not defined



    附:explore.py主要代码:

    class ExploreHandler(webapp.RequestHandler):
    def get(self):
    site = GetSite()
    browser = detect(self.request)
    member = False
    template_values = {}
    template_values['site'] = site
    template_values['page_title'] = site.title + u' 浏览发现'
    template_values['system_version'] = SYSTEM_VERSION
    l10n = GetMessages(self, member, site)
    template_values['l10n'] = l10n
    cookies = Cookies(self, max_age = 86400, path = '/')
    del cookies['auth']
    path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'explore.html')
    output = template.render(path, template_values)
    self.response.out.write(output)



    def main():
    application = webapp.WSGIApplication([
    ('/explore', ExploreHandler)
    ],
    debug=True)
    util.run_wsgi_app(application)


    if __name__ == '__main__':
    main()
    10 条回复    1970-01-01 08:00:00 +08:00
    paloalto
        1
    paloalto  
    OP
       2010-11-17 13:02:06 +08:00
    我不明白为什么说NameError: name 'self' is not defined
    Livid
        2
    Livid  
    MOD
    PRO
       2010-11-17 13:02:22 +08:00
    请 Google 以下关键字:

    Python 缩进
    paloalto
        3
    paloalto  
    OP
       2010-11-17 13:05:54 +08:00
    上面explore.py里没有缩进似乎是因为发出来就给过滤了。。源文件里是有缩进的。
    paloalto
        4
    paloalto  
    OP
       2010-11-17 13:06:54 +08:00
    class ExploreHandler(webapp.RequestHandler):
    def get(self):
    site = GetSite()
    browser = detect(self.request)
    member = False
    template_values = {}
    template_values['site'] = site
    template_values['page_title'] = site.title + u' 浏览发现'
    template_values['system_version'] = SYSTEM_VERSION
    l10n = GetMessages(self, member, site)
    template_values['l10n'] = l10n
    cookies = Cookies(self, max_age = 86400, path = '/')
    del cookies['auth']
    path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'explore.html')
    output = template.render(path, template_values)
    self.response.out.write(output)
    paloalto
        5
    paloalto  
    OP
       2010-11-17 13:09:07 +08:00
    又试了一下,加上空格还是没有显示出来
    源代码截图:

    http://cl.ly/2P2X3O0v3A2M250y1I0C
    Livid
        6
    Livid  
    MOD
    PRO
       2010-11-17 13:13:20 +08:00
    如果是截图上这样的,那么应该是可以运行的。
    paloalto
        7
    paloalto  
    OP
       2010-11-17 13:41:36 +08:00
    @Livid

    http://cl.ly/3c3J2k3h2G3k08291v28

    从昨晚一直在调这个……Orz
    daqing
        8
    daqing  
       2010-11-17 14:24:51 +08:00
    建议你用Python Debugger单步调试: http://docs.python.org/library/pdb.html
    paloalto
        9
    paloalto  
    OP
       2010-11-17 14:54:50 +08:00/span>
    @daqing 哈哈哈,我解决了。我把新加的这个页面加到page.py就行啦
    paloalto
        10
    paloalto  
    OP
       2010-11-17 14:55:00 +08:00
    谢谢大家~~
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2811 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 22ms UTC 14:00 PVG 22:00 LAX 06:00 JFK 09:00
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86