pythonhtmlflaskjinja2

Include file with a path that is a variable (Flask/Jinja2)


Is there some way to make this work in flask (this is in a html template)?

{% include "posts/{{post}}" %}

I expected this to redirect to "/posts/(whatever the post var is - in this case 5)", however it actually redirects to "/post/{{post}}"


Solution

  • I believe one cannot use expansion with {{ }} inside a {% %} block. I would try to concatenate the path:

    {% include "posts/" + post %}