Back to if statements Let's revise what we've learnt so far

Adding SSL to Flask

If you open a website in your browser the chances are that it uses SSL. This means that the web address starts with “https://” instead of “http://”. It also makes the website more secure, as encryption keys are used.

The simplest way to do this is to use PyOpenSSL, an open source cryptography library. You can read more about it on it's website here.

We’ll need to install it using pip: “pip install pyopenssl”

Then when we run flask from the command line, we use “flask run --cert=adhoc”. Note the addition at the end, that tells the compiler to generate a certificate at the time of the connection.

In our browser we need to change the address we’re using from “localhost:5000” to “https://localhost:5000”.

You’ll notice that when you open the website that it comes up with a message saying that the site is not secure. This is because the certificate has not been signed. We know that it’s our computer though, so can safely click on the more details button and continue to the site.

Back to if statements Return to top Let's revise what we've learnt so far