Making a HTML response

We can now start to use our new Jinja2 dependency in our WebServer. First, we need to include it in our imports of service.py:

from .dependencies.jinja2 import Jinja2 

Let's now amend our WebServer class to be the following:

class WebServer: 
 
    name = 'web_server' 
    message_service = RpcProxy('message_service') 
    templates = Jinja2() 
 
    @http('GET', '/') 
    def home(self, request): 
        messages = self.message_service.get_all_messages() 
        rendered_template = self.templates.render_home(messages) 
 
        return rendered_template 

Notice how we have assigned a new attribute, templates, like we did earlier in our MessageService with message_store. Our HTTP entrypoint now talks to our MessageService, retrieves all of the messages in Redis, and uses ...

Get Python Programming Blueprints 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.