Search on blog:

Python: How to use JavaScript in Flask to create dynamic updated page without reloading to display suggestions.

from flask import Flask, render_template, request
import requests
from bs4 import BeautifulSoup

app = Flask(__name__)

def index():
    return render_template('index.html')

def suggestions():
    text = request.args.get('jsdata')

    suggestions_list = []

    if text:
        r = requests.get('{}&gl=in'.format(text))

        soup = BeautifulSoup(r.content, 'lxml')

        suggestions = soup.find_all('suggestion')

        for suggestion in suggestions:


    return render_template('suggestions.html', suggestions=suggestions_list)

if __name__ == '__main__':


<!DOCTYPE html>




Search: <input type="text" id="search_form_input"></input>

<div id="place_for_suggestions"></div>

<script src=""></script>

    var text = $(this).val();

      url: "/suggestions",
      type: "get",
      data: {jsdata: text},
      success: function(response) {
      error: function(xhr) {
        //Do Something to handle error


<label id="value_lable">
    {% for suggestion in suggestions %}
        {{ suggestion }}<br>
    {% endfor %}


Stackoverflow Flask Dynamic data update without reload page

If you like it
Buy a Coffee