Replies: 1 comment
-
The example you linked already does that. Look for |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to learn Rust by porting an existing Python Flask application to Actix Web and Minijinja, and one of the things the app relies on is the Flask Standard Context:
https://flask.palletsprojects.com/en/2.3.x/templating/#standard-context
In particular, the app uses the
g.user
object which contains user information that is injected for each request, e.g.:{{ g.user.name }}
I have managed to get the user information (from session cookie) injected as extension data from a custom Actix Web middleware function, so it is available on the HttpRequest. The problem I'm having is getting the user information automatically injected into the
g.user
object in the Minijinja template, without requiring each route function to inject it explicitly via the template render context.My thought was to use Minijinja's add_global method passing in a function to somehow access the ActixWeb HttpRequest object. I thought I could adapt the example provided in response to my earlier question about implementing the
url_for
method: https://github.com/mitsuhiko/minijinja/blob/main/examples/actix-web-demo/src/main.rsHowever, I'm having a lot of trouble getting it to work, mainly the compiler errors related to function traits which are confusing me to no end.
Is this even the right approach, or is there some easier way to do this? It seems like in general there should be some way to auto-inject data from the current request context into the template context to make it available to all render calls.
Beta Was this translation helpful? Give feedback.
All reactions