Build a Flask Web App Tutorial with GitHub Code Examples

Logan Jul 13, 2026

Diving into the world of web development with Flask, a popular Python microframework, is an exciting journey. If you're new to Flask or looking to build your first web application, you've come to the right place. This comprehensive guide will walk you through creating a simple Flask web app, complete with step-by-step instructions and practical examples. Plus, we'll host it on GitHub for easy access and collaboration.

the logo for flask web development, one drop at a time with an image of a chili pepper
the logo for flask web development, one drop at a time with an image of a chili pepper

Before we get started, make sure you have Python and pip installed on your system. If you haven't already, install Flask using pip: `pip install Flask`. Let's begin!

the differences between django and flask are shown in this info graphic, which shows how
the differences between django and flask are shown in this info graphic, which shows how

Setting Up Your Flask Project

First, create a new directory for your project and navigate into it:

Django vs Flask: Which Python Framework Should You Learn First?
Django vs Flask: Which Python Framework Should You Learn First?

mkdir my_flask_app
cd my_flask_app

Initializing with Pipenv

Liquid button animation using HTML CSS
Liquid button animation using HTML CSS

To manage your project's dependencies, install pipenv: `pip install pipenv`. Then, initialize it in your project directory:

pipenv --three
pipenv install Flask

Now, `Flask` is installed in your virtual environment, and pipenv ensures you're using Python 3.

Complete Beginner’s Guide to Git and GitHub for 2025
Complete Beginner’s Guide to Git and GitHub for 2025

Creating the Basic Structure

Create a new file called `app.py` in your project folder. This will be the entry point for your Flask application. Also, create a folder named `templates` to store your HTML templates:

touch app.py
mkdir templates

Flask Web Development with Python Tutorial - 1 - Basic App
Flask Web Development with Python Tutorial - 1 - Basic App

Building Your Flask Web App

Let's create a simple "Hello, World!" web app to get started.

GitHub · Change is constant. GitHub keeps you ahead. Amazing Travel Destinations, Customer Stories, Software Engineer, Cloud Based, Software Development, Travel Destinations, Software, Start Up, Coding
GitHub · Change is constant. GitHub keeps you ahead. Amazing Travel Destinations, Customer Stories, Software Engineer, Cloud Based, Software Development, Travel Destinations, Software, Start Up, Coding
the gif versus github diagram
the gif versus github diagram
Learn Flask [2026] Most Recommended Tutorials
Learn Flask [2026] Most Recommended Tutorials
Python Flask Tutorial 5 - Database with Flask-SQLAlchemy
Python Flask Tutorial 5 - Database with Flask-SQLAlchemy
a person typing on a computer screen with the words liquid glass in front of them
a person typing on a computer screen with the words liquid glass in front of them
Github repos every software developer must know
Github repos every software developer must know
GitHub - jerosoler/Drawflow: Simple flow library 🖥️🖱️
GitHub - jerosoler/Drawflow: Simple flow library 🖥️🖱️
Web design hack
Web design hack
two screens showing different types of web pages
two screens showing different types of web pages
the text reads, easy way to create animated icons for your project on an iphone
the text reads, easy way to create animated icons for your project on an iphone
a bottle of chokeberry beer on a pink and white background with the words chokeberry
a bottle of chokeberry beer on a pink and white background with the words chokeberry
the cover of how to create glass tongue work
the cover of how to create glass tongue work
card flip effect - @rhys_klarn
card flip effect - @rhys_klarn
a laptop computer sitting on top of a bed with text overlaying the image
a laptop computer sitting on top of a bed with text overlaying the image
Git and GitHub Tutorial for Beginners
Git and GitHub Tutorial for Beginners
how to create a glass effect in adobe
how to create a glass effect in adobe
Use this hack to generate assets for your website
Use this hack to generate assets for your website
Open Online VS CODE from GitHub
Open Online VS CODE from GitHub
a coffee cup with the words css tutor on it
a coffee cup with the words css tutor on it
an image of some type of buttons and numbers on a gray background, with the text below it
an image of some type of buttons and numbers on a gray background, with the text below it

Defining Routes

Open `app.py` and import the Flask module. Then, create a new Flask application and define a route for the homepage (`/`) that returns "Hello, World!":

from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello, World!'

To run your application, add the following lines at the bottom of `app.py`:

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

Rendering Templates

Let's enhance our web app by creating an HTML template. In your `templates` folder, create a new file called `home.html`:

mkdir templates
touch templates/home.html

Add the following content to `home.html`:

<!DOCTYPE html>
<html>
<head>
<title>My Flask App</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>

Now, modify the `home()` function in `app.py` to render the `home.html` template:

from flask import render_template
...
@app.route('/')
def home():
return render_template('home.html')

Running and Deploying Your Flask Web App on GitHub

To run your application, use the following command in your terminal:

pipenv run python app.py

You should see your "Hello, World!" message at in your web browser.

Pushing to GitHub

To deploy your web app on GitHub, create a new repository, and push your project files there:

git init
git add .
git commit -m 'Initial commit'
git remote add origin <your-repo-url>
git push -u origin main

Using GitHub Pages

To expose your web app to the world, create a new file named `.nojekyll` in your project root folder. This prevents GitHub Pages from treating your repository as a Jekyll site. Then, create or modify the `gh-pages` branch in your repository settings, and set the source to the root directory ("/"):

echo "" > .nojekyll
git add .nojekyll
git commit -m 'Add .nojekyll file'
git branch -M gh-pages
git push origin gh-pages

Now, your Flask web app should be live at

Congratulations! You've just created and deployed your first Flask web app on GitHub. This is just the beginning of your web development journey. Keep experimenting, building, and sharing your projects on GitHub to learn and grow. Happy coding!