Join our FREE personalized newsletter for news, trends, and insights that matter to everyone in America

Newsletter
New

Web Development With Python: Build Apis And Web Applications Using Fastapi Or Django

Card image cap

Web development is one of the most practical ways to turn Python knowledge into real-world projects.

Photo by Andy Holmes on Unsplash

You can use Python to build websites, develop backend systems, create REST APIs, connect databases, manage user accounts, and power applications that serve thousands of users.

But here’s something many beginners don’t realize: you don’t need to learn an entirely new programming language to start building the backend of a web application.

If you already know Python, two frameworks are worth exploring: FastAPI and Django.

Both help you build web applications, but they approach development differently. Understanding when to use each one can save you a lot of time.

Let’s explore how they work, what you can build with them, and how to get started.

1. What Is Python Web Development?

A web application usually has three major parts:

  • Frontend: The interface users interact with, built using technologies such as HTML, CSS, and JavaScript.
  • Backend: The server-side logic that processes requests, handles authentication, and performs operations.
  • Database: The system that stores information such as user accounts, orders, products, and transactions.

Python frameworks help you build the backend.

For example, imagine creating an online shopping application.

When a customer opens a product page, the frontend sends a request to the backend. The Python application retrieves product information from the database and returns it to the frontend.

The frontend then displays the information to the customer.

This entire process can be managed using Python.

2. FastAPI: Build Modern APIs With Python

FastAPI has become an attractive option for developers who want to build modern APIs with Python.

It is designed around Python type hints and supports asynchronous programming.

One of its biggest advantages is automatic API documentation.

You don’t need to manually create a separate documentation page for every endpoint. FastAPI can generate interactive documentation from your application.

Build Your First API With FastAPI

First, install FastAPI and its development server.

pip install "fastapi[standard]"

Create a file called main.py.

from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def home():
return {"message": "Welcome to my first API!"}
@app.get("/users/{user_id}")
def get_user(user_id: int):
return {
"user_id": user_id,
"name": "Ali"
}

Start your application:

fastapi dev main.py

Your application will run locally, usually at:

http://127.0.0.1:8000

Open the interactive documentation at:

http://127.0.0.1:8000/docs

You can test your endpoints directly from the browser.

What Just Happened?

Let’s understand the code.

  • FastAPI() creates your application
  • @app.get("/") defines an endpoint that responds to GET requests.
  • @app.get("/users/{user_id}") creates a route with a dynamic parameter.
  • user_id: int tells FastAPI to expect an integer.
  • return sends the response as JSON.

That’s it. You’ve built a working API using just a few lines of Python.

Build a More Useful API

Now imagine creating a simple task management application.

Users should be able to add tasks, view them, and mark them as completed.

from fastapi import FastAPI
app = FastAPI()
tasks = []
@app.post("/tasks")
def create_task(task: dict):
tasks.append(task)
return {
"message": "Task created",
"task": task
}
@app.get("/tasks")
def get_tasks():
return tasks

This example stores tasks in memory, so the information disappears when the application restarts. A real application would use a database.

However, it demonstrates how quickly you can create API functionality.

When Should You Use FastAPI?

FastAPI is particularly useful when building:

  • REST APIs.
  • Backend services for mobile applications.
  • AI-powered applications.
  • Machine learning model APIs.
  • Microservices.
  • Data processing services.

If you want to build a Python backend that communicates with a frontend or another application, FastAPI is an excellent starting point.

3. Django: Build Complete Web Applications

FastAPI focuses heavily on API development.

Django takes a more comprehensive approach.

It is a high-level Python web framework that provides many features out of the box.

Instead of installing separate packages for every basic requirement, Django already includes tools for:

  • User authentication.
  • Database management.
  • URL routing.
  • Form handling.
  • Security protections.
  • An administrative dashboard.

Template rendering.

This makes Django particularly useful for applications that need a complete backend structure.

Build Your First Django Project

Start by installing Django.

pip install django

Create a new project:

django-admin startproject myproject

Move into the project directory:

cd myproject

Start the development server:

python manage.py runserver

Open your browser:

http://127.0.0.1:8000/

You should see Django’s default welcome page.

You’ve successfully created your first Django project.

Create Your First Django App

A Django project can contain multiple applications.

For example, an e-commerce project might have separate apps for products, customers, and orders.

Create an application:

python manage.py startapp products

Inside the products application, open views.py.

Add this code:

from django.http import JsonResponse
def product_list(request):
products = [
{"id": 1, "name": "Laptop"},
{"id": 2, "name": "Keyboard"},
{"id": 3, "name": "Mouse"}
]
return JsonResponse({
"products": products
})

Now create a urls.py file inside the products folder.

from django.urls import path
from .views import product_list
urlpatterns = [
path("products/", product_list)
]

Connect the application URLs to your main project’s urls.py:

from django.contrib import admin
from djangourls import path, incl
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("products.urls")),
]

You also need to add "products" to INSTALLED_APPS in your project's settings.py.

Now visit:

http://127.0.0.1:8000/products/

Your browser will display a JSON response containing the products.

This is a simple example, but it demonstrates how Django handles requests and returns information.

When Should You Use Django?

Django is particularly useful for:

E-commerce platforms.

  • Content management systems.
  • Business management applications.
  • Customer portals.
  • Booking systems.
  • Large database-driven websites.

If you want to build a complete application with authentication, database models, and an administrative interface, Django gives you a strong foundation.

4. FastAPI vs. Django: Which One Should You Learn?

Both frameworks are powerful, but they solve slightly different problems.

FeatureFastAPIDjangoMain focusAPI developmentComplete web applicationsLearning curveRelatively lightweightMore concepts to learn Automatic API documentation Built-in Usually requires additional toolsDatabase toolsChoose your preferred integrationsBuilt-in ORMAuthenticationAdd and configure componentsBuilt-in authentication systemAdmin dashboardNot included by default Built-in Async support Designed with async supportSupports asynchronous views and other async features Best suited forAPIs and backend servicesFull-featured web applications

My Recommendation

If you’re new to Python web development, start with FastAPI.

You can build small APIs, understand HTTP requests, work with JSON, and learn how frontend applications communicate with backend services.

After that, explore Django.

Learning both gives you more flexibility when choosing the right framework for a project.

Remember: neither framework is universally better. The right choice depends on the application you’re building.

5. Connect Your Application to a Database

A web application becomes much more useful when it can store information permanently.

Imagine building a task management application.

You don’t want users to lose their tasks every time the server restarts.

This is where databases come in.

Common database options include:

  • SQLite — A lightweight database suitable for learning and smaller applications.
  • PostgreSQL — A powerful relational database used in many production systems.
  • MySQL — Another widely used relational database.

For example, SQLAlchemy can help you work with relational databases in a FastAPI application.

Django provides its own Object-Relational Mapper (ORM), allowing you to interact with database records using Python classes.

Here’s a simple Django model:

from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(
max_digits=10,
decimal_places=2
)
stock = modelsIntegerField(default=0)
def __str__(self):
return self.name

This defines a product with a name, price, and stock quantity.

After creating the model, run:

python manage.py makemigrations
python manage.py migrate

Django creates the corresponding database structure.

Now your application has a foundation for storing real product information.

6. Build These 5 Projects to Practice Web Development

Reading documentation is useful, but building projects is where you actually develop your skills.

Here are five practical ideas.

Project 1: Personal Expense Tracker

<AsyncImage query=”personal expense tracker web dashboard income expense charts interface” aspectRatio=”16:9" />

Create an application where users can record their daily expenses.

Features

  • Add and delete transactions.
  • Categorize expenses.
  • Calculate monthly spending.
  • Display expense summaries.
  • Store records in a database.

Recommended framework: Django.

This project teaches you database models, forms, authentication, and dashboard development.

Project 2: URL Shortener

<AsyncImage query=”URL shortener web application dashboard interface” aspectRatio=”16:9" />

Build a service that converts long URLs into shorter links.

Features

  • Submit a long URL.
  • Generate a unique short code.
  • Redirect users to the original URL.
  • Track the number of clicks.
  • Display link statistics.

Recommended framework: FastAPI.

This project helps you understand API endpoints, database operations, and HTTP redirects.

Project 3: AI-Powered PDF Summarizer

<AsyncImage query=”AI PDF document summarizer web application interface” aspectRatio=”16:9" />

Build an application that extracts text from PDF files and generates summaries using an AI model.

Features:

  • Upload PDF documents.
  • Extract text using PyMuPDF.
  • Send extracted content to an AI model.
  • Generate summaries.
  • Allow users to download results.

Recommended framework: FastAPI.

This is an excellent way to combine Python web development with AI.

Project 4: Inventory Management System

<AsyncImage query=”inventory management software dashboard products stock levels interface” aspectRatio=”16:9" />

Create a system that helps small businesses manage their inventory.

Features:

  • Add and update products.
  • Track available stock.
  • Record incoming and outgoing inventory.
  • Generate low-stock alerts.
  • Display inventory reports.

Recommended framework: Django.

This project teaches you how to build database-driven business applications.

Project 5: Job Application Tracker

<AsyncImage query=” job application tracking dashboard web app interface” aspectRatio=”16:9" />

Build a dashboard that helps users organize their job applications.

Features:

  • Save company names.
  • Record application dates.
  • Track application status.
  • Add interview notes.
  • Display application statistics.

Recommended framework: Django.

This is a practical project that demonstrates CRUD operations, user accounts, and dashboard design.

7. Skills You Need Beyond FastAPI and Django

Learning a framework is only one part of becoming a web developer.

To build applications that people can actually use, you should understand the technologies surrounding it.

Skill | Why it matters: HTML and CSS: Build the structure and appearance of web pages. JavaScript: Add interactive frontend functionality. HTTP and REST: Understand communication between clients and servers. SQL: Work with databases. Git and GitHub: Track and manage code changes. Authentication: Protect user accounts and application data. Testing: Find errors before deployment. Deployment: Make applications accessible online

You don’t need to master everything before building your first project.

Learn each skill as your application requires it.

8. A Simple 30-Day Learning Roadmap

If you’re starting with Python and want to move into web development, here’s a practical learning plan.

TimelineWhat to learnWhat to buildDays 1–5HTTP, JSON, APIs, requestsSimple APIDays 6–10FastAPI, routes, parametersTask management APIDays 11–15Database basics and SQLAPI connected to a databaseDays 16–20Authentication and validationUser login systemDays 21–25Django fundamentalsBasic CRUD applicationDays 26–30Testing and deploymentDeploy a complete project

By the end, aim to have at least two working projects on GitHub.

The goal isn’t to become an expert in 30 days. It’s to build enough practical experience to understand how real web applications work.

Final Thoughts

Python web development offers much more than creating simple websites.

With FastAPI, you can build modern APIs that connect applications, AI models, and databases.

With Django, you can develop complete business applications with authentication, database management, and administrative tools.

The best way to learn is to stop treating frameworks as something you only study and start using them to solve actual problems.

Choose one project, build its backend, connect a database, test the endpoints, and deploy it.

Don’t just learn Python. Build something people can actually use with it.


Web Development with Python: Build APIs and Web Applications Using FastAPI or Django was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.