O'Reilly logo

Learning Flask Framework by Charles Leifer, Matt Copperwaite

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading comments using AJAX

Now that we are able to create validated comments using AJAX, let's use the API to retrieve the list of comments and display them beneath the blog entry. To do this, we will read the values from the API and dynamically create DOM elements to display the comments. As you might recall from the earlier API responses we examined, there is quite a bit of private information being returned, including the entire serialized representation of each comment's associated Entry. For our purposes, this information is redundant and will furthermore waste bandwidth.

Let's begin by doing a bit of additional configuration to our comments endpoint to restrict the Comment fields we return. In api.py, make the following addition to the call ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required