0

Kind of a conceptual question here. In a Flask app, I'd like to introduce an intermediate confirmation page to the user, before firing the next complex action that requires the Flask request object. If it were possible to store the original request object in session, load the confirmation page, then upon confirmation, pull the original request object out and execute a function based on it, that would be swell. But unless I'm missing something, Flask request objects are not easily serializable, and thus, not easily stored in session, or other DB's.

The question proper: is it possible to somehow save a Flask request object in all it's glory, perform an unrelated request / response cycle, then return to that original request object? Or there is another pattern altogether that might be a better approach? I'd like to avoid picking out the relevant request parameters and serializing those, as this will apply to a wide swath of pages, with very different inputs into the request.

Thought about before_request functions in Flask, but the confirmation page needs user input, from a HTML rendered page. Any thoughts or suggestions would be greatly appreicated.

ghukill
  • 1,136
  • 17
  • 42
  • 1
    this question might be related and help you. It is what I would do personally. http://stackoverflow.com/questions/13617231/how-to-use-g-user-global-in-flask – corvid Aug 13 '14 at 19:47
  • Might be useful if you show an example of what information from the request object you need to save. My first thought is that you can dump the information from the original request into the confirmation page, then when the user confirms that page that info is sent again in the second request. – Miguel Grinberg Aug 13 '14 at 21:27
  • @corvid, that's exactly the kind of thing I was looking for, thanks. Miguel, that would make sense, but to future-proof, need to assume the request object could contain just about anything. – ghukill Aug 14 '14 at 15:48
  • I spoke too soon. I misunderstood, it would seem that ascribing objects to `g` will not span new requests. You can automatically set `g.request`, for example, using the `before_request()`, but I only want to set it in certain cases, not every request. Still searching for a good solution... – ghukill Aug 14 '14 at 18:50
  • Had a secondary thought to begin task as a celery task, pause it, then restart after confirmation. But it knocks up against a limitation of even celery tasks, that you cannot pass the Flask request object as it is not serializable. That's the kicker, the serialization.... – ghukill Aug 14 '14 at 19:08
  • could you provide an example use case? – corvid Aug 14 '14 at 22:59

0 Answers0