这是一个创建于 5088 天前的主题,其中的信息可能已经有所发展或是发生改变。
我想新加一个功能,就是一个静态的图片展示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
|
|
1
paloalto 2010-11-17 13:02:06 +08:00
我不明白为什么说NameError: name 'self' is not defined
|
|
|
2
Livid 2010-11-17 13:02:22 +08:00
请 Google 以下关键字:
Python 缩进
|
|
|
3
paloalto 2010-11-17 13:05:54 +08:00
上面explore.py里没有缩进似乎是因为发出来就给过滤了。。源文件里是有缩进的。
|
|
|
4
paloalto 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)
|
|
|
6
Livid 2010-11-17 13:13:20 +08:00
如果是截图上这样的,那么应该是可以运行的。
|
|
|
8
daqing 2010-11-17 14:24:51 +08:00
|
|
|
9
paloalto 2010-11-17 14:54:50 +08:00
@ daqing 哈哈哈,我解决了。我把新加的这个页面加到page.py就行啦
|
|
|
10
paloalto 2010-11-17 14:55:00 +08:00
谢谢大家~~
|