Flask 2.0 !!!

What’s New

Drop support for Python 2 and 3.5.

Type Hinting

def add(param1, param2):
total = param1 + param2
return total
def add(param1: int, param2:int) -> int:
total = param1 + param2
return total

Load config from any file

import tomlfrom flask import Flaskapp = Flask('__name__')
app.config.from_file('config.toml', toml.load)

New HTTP Method Specific Decorators

from flask import Flaskapp = Flask('__name__')@app.route('/first', methods=['GET'])
def my_get_endpoint():
return 'This was a GET request.'
@app.route('/second', methods=['POST'])
def my_post_endpoint():
return 'This was a POST request.'
@app.route('/third', methods=['PUT'])
def my_put_endpoint():
return 'This was a PUT request.'
from flask import Flaskapp = Flask('__name__')@app.get('/first')
def my_get_endpoint():
return 'This was a GET request.'
@app.post('/second')
def my_post_endpoint():
return 'This was a POST request.'
@app.put('/third')
def my_put_endpoint():
return 'This was a PUT request.'
  • Set the default encoding to “UTF-8” when loading .env and .flaskenv files to allow to use non-ASCII characters.
  • register_blueprint takes a name option to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for url_for. Registering the same blueprint with the same name multiple times is deprecated.
  • Combine URL prefixes when nesting blueprints that were created with a url_prefix value.

How to upgrade ?

pip install -U Flask==2.0.0

Wrapping up

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Saini

Abhishek Saini

Software Developer with expertise in design and building RestAPI’s and micro-services for product. Enjoy reading technical blogs and solving coding problems.