donut
donut

Reputation: 9507

Get the request uri outside of a RequestHandler in Google App Engine (Python)

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.

Upvotes: 1

Views: 811

Answers (2)

Denis Otkidach
Denis Otkidach

Reputation: 33190

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.

Upvotes: 0

Wooble
Wooble

Reputation: 89847

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.

Upvotes: 2

Related Questions