0

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) }}
Ansh
  • 3
  • 1

1 Answers1

0

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.

mikulatomas
  • 330
  • 1
  • 12