How to use HTTPS with Flask for local development

Felipe F Garcia
The Dev Project
Published in
3 min readJul 22, 2020

--

Photo by Pixabay from Pexels

You may come to a situation where you will need to use HTTPS for your application, and this can be for various reasons.

Besides it’s a good practice in production at least you use HTTPS, when it’s about local development it’s really simple, you may need to use for example if you are implementing any social network, that they require that even when testing to use HTTPS otherwise they don’t allow you.

Here I will show you how easy you can make it for development.

First, the easiest one that you can have is, first install the pyopenssl library:

pip install pyopenssl

After you have installed it, you can start using Werkzeug certificates, it’s supported on-the-fly certificates for this server, it’s the one that is built in on Flask for development.

The use will be simple as use Flask CLI command:

flask run --cert=adhoc

Or you can do it directly in your code, for example, this start code:

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(ssl_context='adhoc')

--

--

Felipe F Garcia
The Dev Project

Backend Engineer 💻 Java 👾 Python 🐍 Top Writer in Medium at the topic Technology 🚀 With a mindset to help and share knowledge 📖.