3 ms·
Just to elaborate on what you are saying, I'll write a pythonic version of the handleBlogPostRequest described in the article. This example is a line by line co
by yummyfajitas 17y ago
Just to elaborate on what you are saying, I'll write a pythonic version of the handleBlogPostRequest described in the article. This example is a line by line copy of the one in the post, no real library is used.
def handleBlogPostRequest(request, response, postSlug):
db = yield DBClient()
post = yield getBlogPost(postSlug)
comments = yield db.getComments(post.id)
html = template.render('blog/post.html',
{'post': post, 'comments': comments});
response.write(html)
response.close()
The 'yield' command turns the result of handleBlogPostRequest into a generator. When you "yield getBLogPost(...)", the generator returns a request to the database for a blogpost. When it is ready, the framework passes it back into the generator and assigns the result to post.