2014-02-23 45 views
1

我有一个Appengine应用程序运行良好,但是,有一些代码,我想为每个请求运行,但我不想将它添加到每个单个Python文件(这很麻烦,而且需要很长时间)。有什么办法告诉app.yaml运行一个python文件,然后运行另一个?Python Appengine在执行某些代码之前跟在app.yaml

例如;

#run this; 
- url: .* 
script: everyrequest.app 

#Now run this; 

- url: /mypage/.* 
script: myscript.app 

这可能吗?或者我只需要将代码添加到所有的Python文件中?

回答

1

您可以使用appengine_config.py,它运行的每一个新的实例或使用request_handler的初始化像webapp2的:

class MainHandler(webapp2.RequestHandler): 

    def __init__(self, request, response): 

     super(MainHandler, self).__init__(request, response)          

     .... your code here .... 
相关问题