0

How to link a html button to a Python script -Flask

Hi! I'm new in Python and Flask. I'm trying to make a website where in a page is a modal made with Bootstrap. In this modal, the user should write a title , and then press a button for searching. I have a Python script which compute recommendation. The idea is : I don't know how to link the input from the modal to be the parameter for the python function, and then return the output of the function in the modal. This is the Python function: def authors_recommendations(title): idx = indices[title] sim_scores = list(enumerate(cosine_sim[idx])) sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True) sim_scores = sim_scores[1:21] book_indices = [i[0] for i in sim_scores] return titles.iloc[book_indices] print(authors_recommendations(title).head(20)) This is the modal: <div class="modal-body"> <form action="/cautare" method="POST"> <label for="titlu" class="col-form-label">Introdu titlul ultimei carti citite:</label> <input type="text" class="form-control" id="titlu" placeholder="Titlul_cartii"> <input type="hidden" id="tip"> <div id="raspuns"></div> </form> </div> <div class="modal-footer"> <!--The button for the searching should be here--> <button id="cautare" >Search</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> Thank you!

4th Jul 2021, 11:35 AM
Amalia Mate
Amalia Mate - avatar
2 odpowiedzi
+ 1
this might help ! https://code.sololearn.com/cQW8LjUvU3QK/?ref=app Also i have added the name attribute in input tag so we could use that attribute to get value of search box in our python code . i am displaying the result in cautare.html file but you can display it in same file as well .
4th Jul 2021, 11:43 PM
Abhay
Abhay - avatar
4th Jul 2021, 2:28 PM
A S Raghuvanshi
A S Raghuvanshi - avatar