Flask Tutorial: Build and Launch Your First Web App in Minutes

Published on: May 8, 2026
Reading time: 7 minutes
Logo do Flask em um fundo branco

Building a web application with Python is easier than many beginners expect. One of the best tools for this is Flask. It is lightweight, simple, and flexible. You can create anything from a personal portfolio to a complete web platform.

In this Flask tutorial, you will learn how Flask works, how to install it, and how to build your first web app step by step. Even if you are new to Python, you can follow this guide without problems.

If you are still learning Python basics, it may help to first read Python for Beginners and how to install Python.

What Is Flask?

Flask is a micro web framework written in Python. A framework is a collection of tools that helps developers create applications faster.

Flask focuses on simplicity. It gives you the essentials needed to build a web app without forcing complex rules.

With Flask, you can:

  • Create websites and dashboards
  • Build APIs
  • Handle forms and user input
  • Connect databases
  • Create login systems
  • Deploy apps online

Many developers like Flask because it is beginner-friendly and highly customizable.

Tip: Flask is an excellent first framework for people starting with web development using Python.

Why Use Flask for Web Development?

There are many Python frameworks available today. Flask remains one of the most popular options because it is fast to learn and practical for real projects.

FeatureFlaskDjango
DifficultyEasyMedium
FlexibilityHighMedium
Built-in FeaturesMinimalMany
Best ForSmall and medium appsLarge platforms

If you want to compare frameworks later, you can also explore what Django is.

Installing Flask on Your Computer

Before creating your first app, you need to install Flask.

First, make sure Python is installed correctly.

Open your terminal or command prompt and run:

Bash
python --version

If Python appears, you are ready.

Now create a virtual environment. This keeps your project organized and avoids package conflicts.

Bash
python -m venv venv

Activate the environment:

Windows:

Bash
venv\Scripts\activate

Mac/Linux:

Bash
source venv/bin/activate

Now install Flask:

Bash
pip install flask

You can learn more about virtual environments in this Python venv guide.

Create Your First Flask App

Now comes the fun part.

Create a file called app.py.

Add the following code:

Python
from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, Flask!"

if __name__ == "__main__":
    app.run(debug=True)

This simple application creates a webpage that displays the text “Hello, Flask!”.

Run the app using:

Bash
python app.py

You should see something similar to this:

Running on http://127.0.0.1:5000/

Open the address in your browser.

Your first Flask web app is now running.

Understanding Flask Routes

Routes tell Flask what content should appear for each URL.

For example:

Python
@app.route("/")
def home():
    return "Home Page"

The slash / represents the homepage.

You can create another route:

Python
@app.route("/about")
def about():
    return "About Page"

Now visiting /about shows different content.

Routes are the foundation of Flask applications.

Using HTML Templates in Flask

Returning plain text works, but real websites use HTML.

Create a folder called templates.

Inside it, create a file called index.html.

HTML
<h1>Welcome to My Flask Website</h1>
<p>This is my first web app.</p>

Now update your Python code:

Python
from flask import Flask, render_template

app = Flask(__name__)

@app.route("/")
def home():
    return render_template("index.html")

if __name__ == "__main__":
    app.run(debug=True)

Flask will now load the HTML page automatically.

This approach helps separate Python logic from website design.

Adding CSS Styling to Your Flask App

Without styling, websites look very plain.

Create a folder named static.

Inside it, create a file called style.css.

CSS
body {
    font-family: Arial;
    background-color: #f4f4f4;
    padding: 40px;
}

Now connect the CSS file inside your HTML:

HTML
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

Your Flask app now has custom styling.

If you want to build more modern interfaces, you may also like this Tailwind CSS project.

Handling User Input with Forms

Interactive applications need forms.

Here is a simple example:

Python
from flask import Flask, request

app = Flask(__name__)

@app.route("/", methods=["GET", "POST"])
def home():
    if request.method == "POST":
        name = request.form["name"]
        return f"Hello, {name}"

    return """
    <form method="POST">
        <input type="text" name="name">
        <button type="submit">Send</button>
    </form>
    """

if __name__ == "__main__":
    app.run(debug=True)

This example asks for the user’s name and displays a greeting.

Forms are essential for login systems, search bars, contact pages, and many other features.

Connecting Flask to Databases

Most modern web applications store data.

Flask works very well with databases like SQLite, MySQL, and PostgreSQL.

SQLite is perfect for beginners because it does not require installation.

Example:

Python
import sqlite3

connection = sqlite3.connect("database.db")

You can use databases to store:

  • User accounts
  • Messages
  • Products
  • Blog posts
  • Application settings

You can also learn more in Python with SQLite and connecting Python to MySQL.

Deploying Your Flask App Online

Running your app locally is useful, but eventually you will want other people to access it online.

You can deploy Flask applications using platforms like:

  • Render
  • Railway
  • PythonAnywhere
  • Heroku alternatives
  • DigitalOcean

Before deployment, create a file called requirements.txt:

Bash
pip freeze > requirements.txt

This file lists all installed packages.

Many hosting platforms automatically use this file during deployment.

You can also explore the official Flask documentation at Flask Docs.

Common Flask Beginner Mistakes

Many beginners face similar problems while learning Flask.

Here are some common issues:

  • Forgetting to activate the virtual environment
  • Typing the wrong route URL
  • Incorrect indentation
  • Missing template folders
  • Not installing Flask properly

If your code shows import errors, check this ImportError guide.

If Flask does not start correctly, verify that Python is installed and available in your terminal.

You can also learn debugging basics in this VS Code debugging tutorial.

What Can You Build with Flask?

Flask is much more powerful than many people think.

Here are some project ideas:

  • Personal portfolios
  • To-do list apps
  • Weather dashboards
  • REST APIs
  • Online stores
  • Admin panels
  • Chat applications
  • Automation dashboards

Many startups begin with Flask because it allows fast development and easy testing.

You can also combine Flask with APIs and automation tools using concepts from REST APIs in Python.

Conclusion

This Flask tutorial showed how simple it is to build a web app with Python. You learned how to install Flask, create routes, use HTML templates, add CSS, process forms, connect databases, and deploy applications online.

Flask is one of the best frameworks for beginners because it removes unnecessary complexity and helps you focus on building real projects quickly.

The best way to improve now is through practice. Start small, experiment with new features, and gradually build larger applications.

Every professional developer started with a simple “Hello, World” project.

Perguntas Frequentes (FAQ)

1. What is Flask in Python?

Flask is a lightweight Python framework used to build websites and web applications.

2. Is Flask good for beginners?

Yes. Flask is simple, flexible, and easier to learn than many other frameworks.

3. Do I need HTML to use Flask?

Basic HTML knowledge helps a lot when building web pages with Flask.

4. Can Flask create APIs?

Yes. Flask is widely used to create REST APIs and backend services.

5. Is Flask free?

Yes. Flask is open-source and completely free to use.

6. Which database works best with Flask?

SQLite is great for beginners, while PostgreSQL is popular for larger apps.

7. Can Flask be used for large projects?

Yes. Many production applications use Flask successfully.

8. How long does it take to learn Flask?

You can learn the basics in a few days with consistent practice.

9. Do I need JavaScript with Flask?

Not always, but JavaScript improves interactive features in web apps.

10. Is Flask better than Django?

Flask is simpler and more flexible. Django includes more built-in features.

Share:

Facebook
WhatsApp
Twitter
LinkedIn

Article content

    Related articles

    Instalador do Python com a opção "Add Python.exe to PATH" marcada
    IDEs and Tools
    Foto do Leandro Hirt

    How to Install Python on Your PC Step-by-Step (2026)

    Python is one of the most popular programming languages in the world. It is beginner-friendly, powerful, and used in many

    Ler mais

    Tempo de leitura: 6 minutos
    08/05/2026
    ícone de loop com o texto 'While' abaixo
    Fundamentals
    Foto do Leandro Hirt

    How to Use While Loops in Python with Practical Examples

    Learning how to use a while loop in Python is one of the biggest steps for beginners. While loops help

    Ler mais

    Tempo de leitura: 6 minutos
    08/05/2026
    notebook com código saindo da tela
    Fundamentals
    Foto do Leandro Hirt

    How to Use Variables in Python: A Complete Beginner’s Guide

    Variables are one of the first things every programmer learns in Python. They help you store information, reuse data, and

    Ler mais

    Tempo de leitura: 6 minutos
    08/05/2026
    Tela do VS Code mostrando o marketplace de extensões com destaque para a extensão Python da Microsoft
    IDEs and Tools
    Foto do Leandro Hirt

    10 Must-Have VS Code Extensions for Python Developers in 2026

    Visual Studio Code is still one of the best code editors for Python developers in 2026. It is lightweight, customizable,

    Ler mais

    Tempo de leitura: 7 minutos
    08/05/2026
    Imagem de um quadro negro com várias interrogações no lugar de lâmpadas, e uma lâmpada conectada no meio
    Fundamentals
    Foto do Leandro Hirt

    How to Use If, Elif, and Else in Python: Master Conditional Logic

    Conditional statements are one of the most important parts of programming. They allow your code to make decisions based on

    Ler mais

    Tempo de leitura: 6 minutos
    08/05/2026
    texto Tkinter com uma interface gráfica dele ao lado
    Projects
    Foto do Leandro Hirt

    Build Your First Desktop App with Python & Tkinter

    Creating desktop applications may sound difficult at first. Many beginners think they need advanced programming skills or complex tools. The

    Ler mais

    Tempo de leitura: 7 minutos
    08/05/2026