如何使appstats在GAE上使用webapp2和扩展路由? [英] How do I get appstats to work with webapp2 and extended routing on GAE?

查看:151
本文介绍了如何使appstats在GAE上使用webapp2和扩展路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Appstats在我的GAE Python应用上工作。我使用的是带有Python 2.7的webapp2。



我遵循 https://developers.google.com/appengine/docs/python/tools/appstats#Setup ,其中包括创建appengine_config.py文件:

  def webapp_add_wsgi_middleware(app):$ b $ from google.appengine.ext.appstats导入记录
app =记录.appstats_wsgi_middleware(app)
返回应用程序

然后将以下代码行添加到我的app.yaml :

  builtins:
- appstats:on

我希望使用Appstats的python应用程序如下所示:

 从google.appengine.api导入webapp2 
从google.appengine.ext导入urlfetch
导入db
导入appengine_config

class MainHandler(webapp2.RequestHandler):
def g et(self):
self.response.write('Hello word!')

app = webapp2.WSGIApplication([
webapp2.Route(r'/ method1 /' ,处理程序= Method1,name ='method1'),
webapp2.Route(r'/ method2 /',handler = Method2,name ='method2'),
webapp2.Route(r'/' ,handler = MainHandler,name ='home')
],debug = True)

(我在阅读 一个应用程序#comment12399013_9738518> Appstats只适用于一个WSGIA应用程序,但这也不起作用)



我面临的问题是我可以在 / _ ah / stats 处看到appstats控制台,但即使对应用程序发出了很多请求,它也不会记录任何内容。



我想知道是否与我使用扩展的URL路由有关?我真的很想使用webapps2扩展路由,所以我希望Appstats没有问题。如果有人对我做错了什么有所了解,这真的会有帮助!



感谢您提前加载!

解决方案

经过多次调查,事实证明,我的问题的答案是一个粗心的错误。我以某种方式在子文件夹而不是根文件夹中创建了 appengine_config.py 文件,并且我没有注意到它,因为我一直在使用IDE。因此,如果有人有这个问题,请确保:


  1. appengine_config.py 位于根文件夹中

  2. appengine_config.py 包含上面提到的代码
  3. li>
  4. app.yaml 包含 appstats:on 作为 builtins:(如果您可以访问 / _ ah / stats ,则此部分配置正确)

它应该可以工作。 :)

I'm trying to get Appstats to work on my GAE Python app. I'm using webapp2 with python 2.7.

I've followed the instructions from https://developers.google.com/appengine/docs/python/tools/appstats#Setup which includes creating the appengine_config.py file:

def webapp_add_wsgi_middleware(app):
    from google.appengine.ext.appstats import recording
    app = recording.appstats_wsgi_middleware(app)
    return app

And adding the following lines to my app.yaml:

builtins:
- appstats: on

The python app I wish to use Appstats on looks something like this:

import webapp2
from google.appengine.api import urlfetch
from google.appengine.ext import db
import appengine_config

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello word!')

app = webapp2.WSGIApplication([
    webapp2.Route(r'/method1/', handler=Method1, name='method1'),
    webapp2.Route(r'/method2/', handler=Method2, name='method2'),
    webapp2.Route(r'/', handler=MainHandler, name='home')
], debug=True)

(I tried import appengine_config after reading the comments from Appstats are only working for one WSGIApplication but that doesn't work neither)

The problem I'm facing is that I can see the appstats console at /_ah/stats but it is not recording anything even after many requests have been made to the app.

I'm wondering if it has anything to do with the fact that I'm using extended URL routes? I'd really like to use webapps2 extended routing, so I hope Appstats doesn't have issues with it. If anyone has any insights on what I'm doing wrong, it will really help!

Thanks loads in advance!

解决方案

After much investigation, it turned out that the answer to my problem was a careless mistake. I had somehow created the appengine_config.py file in a sub folder, rather than the root folder, and I didn't notice it because I had been using an IDE.

So should anyone have this problem, make sure:

  1. appengine_config.py is in the root folder
  2. appengine_config.py contains the code mentioned above
  3. app.yaml contains the appstats: on as a builtins: (If you can access /_ah/stats, this part is configured properly)

And it should work. :)

这篇关于如何使appstats在GAE上使用webapp2和扩展路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆