Home > Net >  Url_for in a string flask
Url_for in a string flask

Time:05-29

I want to return a href in a string. I want to pass a variable to the url_for and i can't make it to work.

      { sortable: false,
        "render": function(data, type, row, meta) {
            return '<a href="{{url_for('details', pr_id=row['PR Number'])}}" >Show additional details</a>';
          }
        }

here, row['PR Number'] should return a variable that would've been used as a parameter for url_for. Any ideea about how I should do that? Thanks.

CodePudding user response:

{ sortable: false,
        "render": function(data, type, row, meta) {
            return '<a href="'   url_for('details', pr_id=row['PR Number'])   '" >Show additional details</a>';
          }
        }

Considering you have your url_for method declared in the code beforehand.

Also, you have not closed all the braces properly.

CodePudding user response:

I couldn't make it work with the url_for so I've decided to do it a bit hardcoded, not the best solution, but maybe it would help someone:

    return '<a href="'   window.location.origin   '/details/'   row['PR Number']  '" >Show additional details</a>';
  • Related