jinja_partials icon indicating copy to clipboard operation
jinja_partials copied to clipboard

Automatically add request to context if it's present.

Open dekoza opened this issue 3 years ago • 3 comments

Passing request to render_partial seems like a frequent pattern, at least in my usecases where I generate links using url_for(). Maybe I'm doing something wrong :wink: It would be great if the request was passed automatically.

dekoza avatar Oct 31 '22 08:10 dekoza

Thanks @dekoza How do you propose we pass the request automatically? Keep in mind that flask.request won't work because this library is used across frameworks (which have different ideas of what a request is).

I'm not against it if it can be done. But I didn't see how to accomplish this.

mikeckennedy avatar Nov 02 '22 15:11 mikeckennedy

It could be done in https://github.com/mikeckennedy/jinja_partials/blob/31e813008dc60d1e8c0e7c2ad0fb6045ae54009a/jinja_partials/init.py#L58

It checks if flask is installed, and if yes, the render function could be replaced with one that automatically injects the context

mkrd avatar Mar 19 '23 15:03 mkrd

Hey @mkrd that code only runs once at start up. How do you propose I get access to each individual request? I'm not against it, just not sure how to accomplish it.

mikeckennedy avatar May 17 '23 01:05 mikeckennedy

Closing for inactivity and I'm not sure where to go with it. But feel free to jump in and revive it.

mikeckennedy avatar Apr 12 '24 16:04 mikeckennedy