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 ...
Get Learning Flask Framework now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.