I have this code in my macro file for flask.
{% macro display_name(name, parameter, parameter_value) %}
<a href="{{ url_for('users_stats',parameter = parameter_value) }}">{{name}}</a>
{% endmacro %}
I am not able to set the value of parameter to what I pass in the function. It is coming as a plain text, How to fix this?
This is how I am calling the function.
{{ display_name("Rahul", 'age', 15) }}
>Solution :
Try kwargs dict unpacking. I recommend research more info later.
{% macro display_name(name, parameter, parameter_value) %}
<a href="{{ url_for('users_stats', **{parameter: parameter_value}) }}">{{name}}</a>
{% endmacro %}
The point is creating dict where keys are names of parameters, values are values of corresponding parameters. Then unpack this dict via ** operator to pass these parameters and values into function.