My very basic experience toying around with the framework
Recently I’ve been working on a portfolio website. I wanted to add a backend to the application, but instead of using technologies that I’ve worked with before (RoR for example), I decided to try to learn a bit of Flask. Flask is a microframework using the Python language that “aims to keep the core simple but extensible.”
Going on from there, I set up my app and started some simple routes. For those who have used the Sinatra Ruby framework or have used basic node/express routing, this syntax should come quickly. The following route returns a simple json object with the key of “route” and the value of “/”. We use the jsonify method from the flask package to properly format the object. Our application will error out if we neglect to do so.
You can also use dynamic routing with Flask using the <> syntax. In this example, I made an array of projects that would be used in my portfolio and pulled the object data from the specified project using the url.
All in all, I’m still very new to Flask, and it will be an exciting journey to continue to learn the framework and continue on into larger python frameworks such as Django. Python was my first programming language, and it feels good to return there. I look forward to the learning ahead!
Quickstart - Flask Documentation (1.1.x)
A minimal Flask application looks something like this: So what did that code do? First we imported the class. An…
flask.json jsonify Example Code
Python example code that shows how to use the jsonify callable from the flask.json module of the Flask project.