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.

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!

Setting Up Your Flask Project
First, create a new directory for your project and navigate into it:

mkdir my_flask_app
cd my_flask_app
Initializing with Pipenv

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.

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

Building Your Flask Web App
Let's create a simple "Hello, World!" web app to get started.


![Learn Flask [2026] Most Recommended Tutorials](https://i.pinimg.com/originals/70/c3/0b/70c30b834f681afe86155783ec72f112.png)

















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
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!