I have a table in a flask template, I am trying to append anchor to it using JavaScript:
Table:
<div class="box-body">
<div class="table-responsive">
<table class="table table-responsive mb-0 table-hover">
<thead class="scroll-x">
</thead>
<tbody id='downloadPredictions'>
</tbody>
</table>
</div>
</div>
JavaScript code:
$('#downloadPredictions').append("<td><a class='btn btn-primary' href='{{ url_for('download_corrected_file', dataset_id=dataset_id) }}'><i class='fa fa-download faicon' aria-hidden='true' title='Download'></i> Download Predictions</a></td>")
It sends following url:
http://127.0.0.1:5000/%7B%7B%20url_for(
I don't know what I am doing wrong in href while appending anchor. Any help please?
You have a syntax error in your JS .Make sure to use the correct quotation marks
$('#downloadPredictions').append("<td><a class='btn btn-primary' href='{{ url_for('download_corrected_file', dataset_id=dataset_id) }}'><i class='fa fa-download faicon' aria-hidden='true' title='Download'></i> Download Predictions</a></td>")
Should be
$('#downloadPredictions').append(`<td><a class='btn btn-primary' href="{{ url_for('download_corrected_file', dataset_id=dataset_id) }}"><i class='fa fa-download faicon' aria-hidden='true' title='Download'></i> Download Predictions</a></td>`)