27
loading...
This website collects cookies to deliver better user experience
Photo by Markus Spiske on Unsplash
2.0.0
.2.0.0
2
and 3.5
. Well, it's about time we move from those versions anyway, since Python 2
is really old!3.5
and 2
support is required for the next change:3.7
added support for type annotations. This is where you can add type hints to variables to tell others what type it will be. This is a God send for people with linters and autocompletors, since you no longer have to view docs to find the return type of a certain function.python
interpreter goesa: str = 5
To check your types, use an external linter like mypy
2.0.0
is now fully typed, so no more awkward moments when you import request
from flask
and your IDE won't autocomplete its methods.2.0.0
and its earlier versions with the help()
function:1.1.4
's docstring and the below image shows Flask 2.0.1
's docstring. Notice the type hintsConfig.from_json()
, or the app.config.from_json()
method that you use to configure Flask with a JSON File. In Flask 2.0.0
, it has been deprecated in favour of Config.from_file
.app.config.from_file(filename: str, loads_function)
from_json
behaviour, look at the code below:import json
app.config.from_file(filename: str, json.load)
TOML
files as well:import toml
app.config.from_file(filename: str, toml.load)
You need to install the toml
package for this!
@app.route(path: str)
to define a route in our app, and for methods other than GET
we add the methods
parameter to our decorator.# You can now use these instead of app.route
@app.get(path)
@app.post(path)
@app.put(path)
@app.delete(path)
@app.patch(path)
send_file
parameters have been renamed, the old names are deprecated. attachment_filename
is renamed to download_name
. cache_timeout
is renamed to max_age
. add_etags
is renamed to etag
..env
or .flaskenv
file, the current working directory is no longer changed to the location of the file.helpers.total_seconds()
is deprecated. Use timedelta.total_seconds()
instead.flask shell
sets up tab and history completion like the default python shell if readline
is installedFlask
dependency in requirements.txt
, Pipfile
or pyproject.toml
to this:Flask==2.0.0
pip3 install -r requirements.txt
You can no longer use python2
, so beware of that!