DEV Community

Cover image for How to Get Started With Flask

Posted on

How to Get Started With Flask

Python is a versatile and open-source programming language that can be used for a range of applications. With Flask, you can create a web app by writing Python code.

Flask is a web framework that's easy to get started with and has powerful features and extensions. It's great to use for your next project because it's simple, unobtrusive, and extensible. The framework has been around for almost 8 years, and in that time it's evolved in a lot of ways.

Why Flask?

Flask is used to develop websites of all sizes and has advantages over other frameworks including:

  • Lightweight and cool
  • Supports extensions - Flask has support for extension packages, which makes it easy to add functionality that you'll need for your application.
  • Easy templating - Flask uses Jinja2 in its default template engine.
  • Full-stack - Flask includes support for unit testing and debugging, something that other frameworks usually require additional libraries to implement.
  • API - Easy to build an API
  • Supports cookies, sessions and other things you'd expect from a web framework

Flask is not intended to be a full-stack framework, it is intended to make development of web applications easier by providing simple modules which solve common problems.

Just like when we first started learning to drive, we don't want to deal with anything except putting the key in the ignition and pressing the gas pedal.

Using Flask feels more like riding a bicycle or typing, less like learning to use an engine crane or shift registers.

If you are new to Flask, this is a good starting course

What does building a Flask app involve?

Building a web application with Flask involves:

  1. Installing Flask and its dependencies
  2. Importing the library
  3. Defining a route
  4. Defining a view function
  5. Registering the view function with the router
  6. (optional) Creating a WSGI application to serve the application
  7. (optional but neat) Running the development server in debug mode
  8. (optional) Configuring Gunicorn to serve the application

You can also just deploy your app online in a few clicks.

Discussion (0)