Forums

Convert words in output to links and get the corresponding value in JSON when clicked

I have a scrabble word generator which lists all possible words for given letters.

Up to now, I can list all possible words in "results" page. What I'd like to do is to convert all possible words into clickable links so that when user clicks on a word, he/she can see the meaning of the word in a new page.

How can I achieve this? Is there more suitable way to create link for the meanings of the words?

My Flask app

@app.route('/result', methods = ['POST'])
def data():
if request.method == 'POST':

   (SOME CODE HERE)

return render_template('result.html',possibleWords=possibleWords)

My result.html page

 <div class="results"><pre>{{possibleWords}}</pre></div>

JSON File

[{
"word": "somewordhere",
"meaning": "meaning of someword"
},
{
"word": "somewordhere2",
"meaning": "meaning of someword 2"
}]

(If you may want to check original website: http://kelimegetir.com)

You can loop through the entries in the template and create the links there: https://flask.palletsprojects.com/en/2.2.x/tutorial/templates/