我有一个应用程序,我想将一些请求处理程序移动到单独的文件中。我已经将问题简化为这个简单的应用程序来演示它。
如果我浏览主页,例如:
http://localhost:12082/
我懂了
'Hello World...'
显示
如果我尝试进入初始化页面,例如:
http://localhost:12082/init/
我懂了
'404 Not Found'
The resource could not be found.
在日志中我看到了这个:(init2 消息永远不会被记录,helper 方法永远不会被调用。)
我究竟做错了什么?谢谢你的任何线索
日志内容:
...
INFO 2014-01-15 20:58:23,384 admin_server.py:117] Starting admin server at: http://localhost:8005
INFO 2014-01-16 04:58:34,398 initter.py:6] init1
INFO 2014-01-16 04:58:34,398 initter.py:17] init3
INFO 2014-01-15 20:58:34,421 module.py:617] default: "GET / HTTP/1.1" 200 14
INFO 2014-01-15 20:58:34,473 module.py:617] default: "GET / HTTP/1.1" 200 14
INFO 2014-01-15 20:58:39,555 module.py:617] default: "GET /init/ HTTP/1.1" 404 154
应用程序.yaml:
application: helloworld
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: helloworld.application
你好世界.py
import webapp2
import initter
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello World...')
application = webapp2.WSGIApplication([
('/', MainPage),
('/init', initter.LoadPeople),
], debug=True)
初始化程序
import webapp2
import logging
logging.getLogger().setLevel(logging.DEBUG)
logging.info("init1")
class LoadPeople(webapp2.RequestHandler):
def get(self):
logging.info("init2")
names = [ 'Joe', 'Jill', 'George', 'John', 'Dave' ]
for name in names:
logging.debug("name is %s", str(name))
logging.info("init3")