Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Django
  • Django, FastAPI or Flask? The Same Blog Feature in Three Shapes, and How to Choose
  • Getting Started with Django: Models, Views, Templates, the ORM and the Admin
  • Your First Django Project and App: uv, startproject, startapp and a First View
  • The Django Project Folder Structure, File by File: Reading a Blog an AI Agent Built
  • How a Request and a Login Flow Through Django: URLconf, ORM, CSRF, Password Hashes and Sessions
  • Testing a Django Blog with pytest-django: Fixtures, the Test Database and the Client
  • One Blog, Three Frameworks: Routing, Models, Templates and Layout in Django, FastAPI and Flask
  • Building a Blog with an AI Coding Agent: Plan Mode, a Master Prompt and the First Review
  • Handing a Figma Design to an AI Agent: Compare the Files, Then Review the Change
  • Django Models, Migrations and the Admin: From a Post Class to a Real Table
  1. Blog
  2. /
  3. Django
  4. /
  5. Fundamentals

One Blog, Three Frameworks: Routing, Models, Templates and Layout in Django, FastAPI and Flask

The same blog built in Django, FastAPI and Flask, compared line by line: the list route, the Post model, the template loop, the project layout and the extras, with a ROSETTA map you can use to port a feature with AI.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Find the list-posts route, the Post model and the template loop in all three blogs
  • Map Django names to their FastAPI and Flask equivalents with a file-and-line table
  • Tell which extras are built in, come from a package or were written by hand
  • Use a feature map as context and as a review checklist when porting with AI

Before you start

  • One finished blog in Django, FastAPI or Flask
  • Python classes and decorators

You built the blog in one framework, and that's the right way to learn. But sooner or later you meet another one: a new job where the team uses a different framework, a teammate who shares code in another one, or a client whose app already runs on one. The good news is that the features stay the same. Only the names and the places change. All you need is a map.

Think of one recipe cooked in three kitchens. The recipe is short: list the posts, store the posts, show a page, let people log in. Django is a fitted kitchen: the oven and cupboards are built in, and each thing goes where the manual says. FastAPI is a kitchen with labelled drawers, and the menu prints itself. Flask is an open kitchen: very little is built in, so you bring your own pans. Learn the recipe once, then learn where each kitchen keeps things.

This article compares the three finished blogs from the course tracks (the S01L05 projects with templates). Every file and line below comes from a map called ROSETTA.md that was checked against the real files.

Routing: an address, a read, a render

Routing answers one question: when someone opens the home address, which code runs?

FastAPI

app/routes/posts.py:

router = APIRouter()
templates = Jinja2Templates(directory="app/templates")


@router.get("/", response_class=HTMLResponse)
async def index(request: Request, db: Session = Depends(get_db)):
    posts = db.query(Post).order_by(Post.created_at.desc()).all()
    user = get_current_user(request, db)
    return templates.TemplateResponse(request=request, name="index.html", context={"posts": posts, "user": user})

Line 13, @router.get("/"), is the address, with index below it. Line 15 reads the posts newest first, and line 17 hands them to the template. In app/main.py, line 40 plugs the router into the app: app.include_router(posts.router, tags=["posts"]).

Django

Django splits the work across two files. blog/urls.py line 5 sends the empty address to the view:

path('', views.home, name='home'),

and blog/views.py reads the published posts (line 14) and renders the page (line 30):

def home(request):
    """Home page displaying all published posts"""
    posts_list = Post.objects.filter(status='published')
    ...
    # Pagination
    paginator = Paginator(posts_list, 6)  # 6 posts per page
    page_number = request.GET.get('page')
    posts = paginator.get_page(page_number)

    return render(request, 'blog/home.html', {'posts': posts, 'search_query': search_query})

The project's blogproject/urls.py line 25 plugs the app in with path('', include('blog.urls')).

Flask

app/routes/blog.py:

bp = Blueprint('blog', __name__)

...

@bp.route('/')
def index():
    page = request.args.get('page', 1, type=int)
    posts = Post.query.order_by(Post.created_at.desc()).paginate(
        page=page, per_page=10, error_out=False)
    return render_template('index.html', posts=posts)

A blueprint is Flask's group of routes. Line 17 is the address, line 20 reads the posts newest first, line 22 renders the page, and app/__init__.py line 47 registers the blueprint with app.register_blueprint(blog.bp).

The same three steps in each framework. Address: FastAPI router.get, Django path in urls.py, Flask bp.route. Read the posts: db.query(Post), Post.objects.filter, Post.query. Render: TemplateResponse, render, render_template. FastAPI Django Flask Address @router.get("/") path('', views.home) @bp.route('/') Read db.query(Post) Post.objects.filter(...) Post.query... Render TemplateResponse render(request, ...) render_template
Address, read the posts, render the page: the same three steps in every kitchen.

The Post model

FastAPI, app/models.py from line 21, built on SQLAlchemy's Base:

class Post(Base):
    __tablename__ = "posts"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String, nullable=False)
    content = Column(Text, nullable=False)
    author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

Django, blog/models.py from line 17, built on models.Model (choice lists left out):

class Post(models.Model):
    ...
    title = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200, unique=True, blank=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='posts')
    content = models.TextField()
    excerpt = models.TextField(max_length=500, blank=True, help_text='Brief summary of the post')
    category = models.CharField(max_length=20, choices=CATEGORY_CHOICES, default='Other')
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')

Django builds the table from these fields with a migration. Flask, app/models.py from line 30, built on db.Model:

class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False)
    slug = db.Column(db.String(200), unique=True, nullable=False, index=True)
    content = db.Column(db.Text, nullable=False)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

Flask reads almost like FastAPI, because both sit on SQLAlchemy. Every post has an id, a title, the content and an author. Only the spelling changes.

Templates: a loop, a link and a title

LoopLink to one post
FastAPI index.htmlline 10: {% for post in posts %}line 12: <a href="/post/{{ post.id }}">{{ post.title }}</a>
Django home.htmlline 71: {% for post in posts %}line 88: <a href="{% url 'post_detail' post.slug %}" ...>{{ post.title }}</a>
Flask index.htmlline 53: {% for post in posts.items[1:] %}line 63: <a href="{{ url_for('blog.post_detail', slug=post.slug) }}" ...>, title on line 64

FastAPI types the link out by hand: /post/ plus the numeric id. This is Jinja2. Django's url tag looks the route up by its name, with the post's slug. Flask's url_for also finds the route by its name, and it's the same Jinja2 as FastAPI. Flask's loop starts from the second post because the first one is shown above it as the featured post. All three pages start by extending a layout, {% extends "base.html" %} (Django: 'blog/base.html').

Project layout

Seed scripts, tests and migrations left out:

  • FastAPI: one app folder with models.py, routes/ and templates/, next to main.py.
  • Django: split by app. The blog app has its models, views, URLs and its own templates folder. blogproject holds the settings, and manage.py runs everything.
  • Flask: one app folder with models, routes and templates; config.py holds the settings and main.py starts it.

Django makes you split by app; FastAPI and Flask let you choose. All three end up with models, routes and templates.

The extras each blog has

ExtraFastAPIDjangoFlask
Adminwritten by us: require_admin, app/auth.py:93built in: path('admin/', admin.site.urls), blogproject/urls.py:24written by us: admin_required, app/routes/admin.py:14
Loginwritten by us on SessionMiddleware, app/main.py:33built in: login_required, blog/views.py:3package: Flask-Login LoginManager(), app/__init__.py:11
Formsbuilt in: title: str = Form(...), app/routes/posts.py:44built in: class PostForm(forms.ModelForm), blog/forms.py:43package: Flask-WTF FlaskForm, app/routes/admin.py:25
API docsbuilt in: docs_url="/docs", app/main.py:19package: drf-spectacular, blogproject/urls.py:30package: Swagger UI blueprint, app/__init__.py:36

Count them: five built in, four from a package, three written by hand. Knowing which one it is tells you where to look.

Proof: each list page answers 200

Each blog was started from a temporary copy, asked for the list page once, and stopped. The recorded run (run_all.md):

BlogVersionGET /Page titlePost linksOther checks
FastAPI0.136.1200Home - Blog6/docs 200
Django6.1.3200Home - Elegant Blog6/admin/login/ 200, /api/docs/ 200
Flask3.1.3200Home - Blog10/api/docs/ 200

Why ten in Flask? Page size. Flask shows ten posts per page (per_page=10, line 21 of blog.py), Django's paginator shows six, and FastAPI lists all of its six posts.

The map, and porting with AI

ROSETTA.md has one row per feature, with the file and line in all three blogs. A few rows:

FeatureFastAPIDjangoFlask
List-posts routeapp/routes/posts.py:13blog/urls.py:5app/routes/blog.py:17
The Post modelapp/models.py:21blog/models.py:17app/models.py:30
Loop over the postsapp/templates/index.html:10blog/templates/blog/home.html:71app/templates/index.html:53
Login supportapp/main.py:33blog/views.py:3app/__init__.py:11
API docsapp/main.py:19blogproject/urls.py:30app/__init__.py:36

To port a blog with AI, start from the map. Take the list-posts row: the Django column says where it is now, the Flask column says where it should go. Five rows become five small jobs you can check, instead of "rewrite my blog". A sample prompt from the lesson's PROMPT.md:

I have a blog written in Django and I want the same blog in Flask.
Use ROSETTA.md as the map. For the list-posts page, find the Django
file and line in each row, then write the Flask version in the place
the Flask column names.
Keep the behaviour: newest post first, and each title links to its post.
Show the result file by file, and list anything the Flask project does
not have yet.

When the answer comes back, check three things. Does every row of the map have a matching change? Do the route names fit the new framework, like url_for or the url tag? Does the list page answer 200? The map is also your review checklist.

Quick recap

ConceptFastAPIDjangoFlask
Group of routesAPIRouterapp urls.pyBlueprint
Model baseSQLAlchemy Basemodels.ModelFlask-SQLAlchemy db.Model
Querydb.query(Post)Post.objectsPost.query
TemplatesJinja2Django templatesJinja2
Link by route name(typed by hand here){% url %}url_for

If you haven't picked a track yet, start with Django, FastAPI or Flask.

Try it yourself

Find the list route of your blog in the map, open the same row in another track, and port just that one route, by hand or with the prompt above. Then send one GET request to the new list page.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in Django · 7 of 10

Previous
Testing a Django Blog with pytest-django: Fixtures, the Test Database and the Client
Next post
Building a Blog with an AI Coding Agent: Plan Mode, a Master Prompt and the First Review

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

Django, FastAPI or Flask? The Same Blog Feature in Three Shapes, and How to Choose

One small project lists two blog posts three times: as a Django view, a Flask route and a FastAPI endpoint. See each shape with its real output, what each framework includes, and a three-question way to choose.

Getting Started with Django: Models, Views, Templates, the ORM and the Admin

A tiny Django menu app with one model, one view, one URL, one template and the admin. What each file does, how one request travels through them, and the real output of a run.

Your First Django Project and App: uv, startproject, startapp and a First View

Set up a Django project called blogproject with uv, add an app called blog, write one view that returns Hello blog, give it the empty path and run the server. Every command with its real output.

The Django Project Folder Structure, File by File: Reading a Blog an AI Agent Built

A tour of a finished Django blog: manage.py, the project package, the blog app with its models, views, templates, forms and admin, a custom command, the REST API and Swagger docs, plus the review points check --deploy found.

On this page

  • Routing: an address, a read, a render
  • FastAPI
  • Django
  • Flask
  • The Post model
  • Templates: a loop, a link and a title
  • Project layout
  • The extras each blog has
  • Proof: each list page answers 200
  • The map, and porting with AI
  • Quick recap
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.