Render Jinja after jQuery AJAX request to Flask

前端 未结 2 813
梦毁少年i
梦毁少年i 2021-02-01 10:56

I have a web application that gets dynamic data from Flask when a select element from HTML is changed. of course that is done via jquer

2条回答
  •  后悔当初
    2021-02-01 11:50

    Okay, I got it.

    Simply, I made an external html file and added the required jinja template to it.

    {% for object in object_list %}
       {{object.name}}
    {% endfor %}
    

    then in my Flask file I literally returned the render_template response to the jquery ( which contained the HTML I wanted to append )

    objects_from_db = getAllObjects()
    return jsonify({'data': render_template('the_temp.html', object_list=objects_from_db)}
    

    And then simply append the HTML from the response to the required div to be updated.

提交回复
热议问题