Creating a Flask server
We will now create a new Flask web server, which will replace our Nameko Web Server. Flask is better suited to handling web requests than Nameko and comes with a lot more baked in while still being fairly lightweight. One of the features we will take advantage of is Sessions, which will allow our server to keep track of who's logged in. It also works with Jinja2 for templating, meaning that our existing template should already work.
Start by adding flask
to our base.in
file, then pip-compile
and install (version 0.12.2 at the time of writing) using the same process as earlier.
Getting started with Flask is quite straightforward; we will start by creating our new home page endpoint. Within your temp_messenger
directory, create a new file, web_server.py
, with the following:
from flask import Flask, render_template # ① app = Flask(__name__) # ② @app.route('/') # ③ def home(): return render_template('home.html') # ④
- We import the following from
flask
:Flask
...