6

Can the flask.request object be used similarly to flask.g to store per-request data?

I am writing a library that is compatible with both Flask and Django. I plan to store information on the request object in both cases. Can I safely store objects on the request, say request.user, with the assurance that it will not be shared between different requests?

davidism
  • 110,080
  • 24
  • 357
  • 317
Panda
  • 548
  • 3
  • 18

1 Answers1

9

Yes, it is safe. The request object is unique per request.

Typically g is used because it is an empty namespace specifically created for holding data during a request.

request is an internal object with existing meaning, although it is common for libraries to use it for storage, leaving g for "application level" data.

davidism
  • 110,080
  • 24
  • 357
  • 317