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

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

  •  
  •   paloalto Nov 17, 2010 5055 views
    This topic created in 5664 days ago, the information mentioned may be changed or developed.
    我想新加一个功能,就是一个静态的图片展示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 replies    1970-01-01 08:00:00 +08:00
    paloalto
        1
    paloalto  
    OP
       Nov 17, 2010
    我不明白为什么说NameError: name 'self' is not defined
    Livid
        2
    Livid  
    MOD
    PRO
       Nov 17, 2010
    请 Google 以下关键字:

    Python 缩进
    paloalto
        3
    paloalto  
    OP
       Nov 17, 2010
    上面explore.py里没有缩进似乎是因为发出来就给过滤了。。源文件里是有缩进的。
    paloalto
        4
    palalto  
    OP
       Nov 17, 2010
    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
       Nov 17, 2010
    又试了一下,加上空格还是没有显示出来
    源代码截图:

    http://cl.ly/2P2X3O0v3A2M250y1I0C
    Livid
        6
    Livid  
    MOD
    PRO
       Nov 17, 2010
    如果是截图上这样的,那么应该是可以运行的。
    paloalto
        7
    paloalto  
    OP
       Nov 17, 2010
    @Livid

    http://cl.ly/3c3J2k3h2G3k08291v28

    从昨晚一直在调这个……Orz
    daqing
        8
    daqing  
       Nov 17, 2010
    建议你用Python Debugger单步调试: http://docs.python.org/library/pdb.html
    paloalto
        9
    paloalto  
    OP
       Nov 17, 2010
    @daqing 哈哈哈,我解决了。我把新加的这个页面加到page.py就行啦
    paloalto
        10
    paloalto  
    OP
       Nov 17, 2010
    谢谢大家~~
    About     Help     Advertise     Blog     API     FAQ     Solana     2546 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 40ms UTC 16:03 PVG 00:03 LAX 09:03 JFK 12:03
    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