Get the request uri outside of a RequestHandler in

2019-07-22 11:50发布

So, within a webapp.RequestHandler subclass I would use self.request.uri to get the request URI. But, I can't access this outside of a RequestHandler and so no go. Any ideas?

I'm running Python and I'm new at it as well as GAE.

2条回答
冷血范
2楼-- · 2019-07-22 12:27

You should generally be doing everything within some sort of RequestHandler or the equivalent in your non-WebApp framework. However, if you really insist on being stuck in the early 1990s and writing plain CGI scripts, the environment variables SERVER_NAME and PATH_INFO may be what you want; see a CGI reference for more info.

查看更多
我命由我不由天
3楼-- · 2019-07-22 12:27

Since using request outside code handling it is meaningless I assume you'd like to access it from some method called by handler without passing request to it. Your choices are:

  1. Refactor code so that request is passed to it.
  2. When the former is not possible use a hack by defining a global threading.local(), storing request somewhere in request handler and access it in your method.
查看更多
登录 后发表回答