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

Building a Blog with an AI Coding Agent: Plan Mode, a Master Prompt and the First Review

Start from an almost empty folder, ask an AI agent for a plan before any code, run the blog it builds in Django, FastAPI or Flask, then review it: who is allowed to write a post, and how does someone become the admin?

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Write a master prompt in Role, Context, Task and Format that asks for a plan first
  • Read an agent's plan against your prompt before you approve it
  • Run the generated blog yourself and follow one request through it
  • Review the code for who can write a post and how someone becomes the admin

Before you start

  • Basic Python
  • What a web framework does (Django, FastAPI or Flask)

This time we don't type the blog. An AI coding agent writes it. We still stay in charge, though, because we plan it, run it and review it ourselves.

The lecture was recorded three times, once each for Django, FastAPI and Flask. The process is the same in all three, so this article walks through it once. Where the generated code differs, you'll see each framework's version side by side. The differences are where the review gets interesting.

Think about a restaurant kitchen. You write the order ticket. Before anyone lights the stove, the head chef reads it back to you as a plan, step by step, and you cross out the step you didn't want. Only then does the cooking start, and when the dish comes out, you taste it before it goes to a guest. The prompt is the ticket, the plan is the read-back, and the review is the tasting.

From prompt to review in six steps

Six steps: an empty folder, the master prompt, plan mode writes a plan and no files, you read and approve the plan, the agent builds, then you run the blog and review the code. A loop arrow goes from reading the plan back to the prompt. Emptyfolder Masterprompt Plan modeno files yet You readthe plan Agentbuilds You runand review something off? one line, ask for a new plan Plan first, build second
Nothing gets written until you have read the plan and said yes.

An empty folder and plan mode

Each track starts from a folder with a README in it (the Django one also has a .gitignore), and that's all. You've already set up a project by hand earlier in each track, so this time the agent creates the project, the app, the routes and the database.

An agent reads files, runs commands and changes code, and you review the diff. Most agents also have a plan mode. In plan mode the agent reads the folder and writes a plan, but it doesn't touch a single file. You read the plan, approve it, and only then does it start building.

The master prompt

The prompt uses the same four-part frame each time: Role, Context, Task and Format. Here is the FastAPI version as a sample. The other two change the framework words.

PartWhat it says
RoleYou're a senior FastAPI developer who explains each step.
ContextThe folder is empty and we use uv. It's a monolithic app, so FastAPI serves every page with Jinja2 templates, and users log in with a session. The admin's email comes from the .env file. Database: SQLite.
TaskBuild a blog where the admin creates, edits and deletes posts with a free rich text editor, and anyone can register and comment.
FormatPlan first, list the files, and wait for my OK. Then build, and give me the commands to run.

The Format line is what keeps you in control. The three prompts were not identical, and that matters later:

  • Django asked for a blog where anyone can register, log in, write a post and comment, using Django's own login.
  • FastAPI and Flask asked for an admin who writes posts, an admin email taken from .env, and comments for everyone who registers. Flask uses Flask-Login, and the Flask prompt also asked for an editor that needs no API key and for some sample posts.

The Flask lecture adds a good tip: keep the prompt small. Ask for too much at once and the agent starts to miss things.

One database file

One line in the Context is worth a second look: Database, SQLite. SQLite keeps the whole database in one file, so there is nothing to install and nothing to start. Here is where each agent put it:

# Django: blogproject/settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
# FastAPI: app/database.py
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./blog.db")
# Flask: config.py
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
    'sqlite:///' + os.path.join(basedir, 'blog.db')

In Flask, the .env file sets DATABASE_URL=sqlite:///blog.db, a relative path, so Flask-SQLAlchemy puts the file in the instance folder. If you need PostgreSQL later, you change that one line in the prompt and the agent writes PostgreSQL settings instead. For learning, SQLite is all you need.

Reading the plan

When the plan comes back, don't just say yes. Read it against your prompt, point by point:

  1. The shape. One project package and one app called blog (Django), one app package with the routes in their own folder (FastAPI), or the routes split into blueprints (Flask)?
  2. The data. Users, posts and comments, and does every post belong to an author?
  3. The stack. The login you asked for, SQLite, and no extra packages you didn't ask for.
  4. Anything missing. You asked for an editor and comments (and, for FastAPI and Flask, an admin from .env), so they should all be in the plan.

If something is off, say so in one line and ask for a new plan. It takes a minute now and saves you an hour later.

What the agents built

After approval, each agent filled the folder. A few things stood out:

  • Django: a blogproject package with settings and the main URLs, a blog app with models, views, urls, forms and admin, a templates folder, and a management command called create_sample_posts that nobody asked for. Its migrations folder has three files, not one.
  • FastAPI: an app package with main.py, database.py, models.py, schemas.py and an auth.py, plus a routes folder with auth.py, posts.py and comments.py. So there are two files called auth.py. The first build crashed; the error was pasted back, and sample posts were asked for at the same time, which is where seed_data.py came from.
  • Flask: an app factory, create_app, in app/__init__.py, three blueprints (auth, blog, admin), a config.py, a seed script and two small admin scripts. The requirements file is spelled requirments.txt, and the lecture keeps that name.

The models

All three agents produced the same three ideas: a user, a post that belongs to one author, and a comment that points to its post and its author. The short versions of the Post model:

# Django: blog/models.py
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()
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')
# FastAPI: app/models.py
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)
# Flask: app/models.py
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)

The Django Post.save builds a slug from the title when there isn't one, so "Mastering Git and GitHub for Collaboration" becomes an all-lowercase, dash-joined slug. Each post points to one author in every version, so the data part passes. For a fuller side-by-side of the three projects, see One Blog, Three Frameworks.

Look at the user, though. The FastAPI User has an is_admin column that starts as False. The Flask User has no admin column at all, only a method, is_admin(self, admin_email). Keep that in mind for the review.

Running it ourselves

The agent gives you the commands, and you run them yourself in the terminal:

SetupStartSample data
Djangopython manage.py migrate (Django's tables, then the blog's three migrations)python manage.py runservercreate_sample_posts: a test admin and 6 posts
FastAPIcreate_all builds the tables when the app startsuvicorn app.main:app on port 8000python seed_data.py: an admin, a regular user, 5 posts, 3 comments
Flaskuv venv, then uv pip install -r requirments.txt (19 packages, Flask 3.1.3)python main.py, debug mode, port 5000python seed_data.py: an admin, 4 users, 10 posts

The seeded passwords are made up for these test databases only. In every track the first GET / came back with 200, and the home page listed the sample posts.

One request through the home page looks the same in all three: the URL is matched to a function (views.home, index in routes/posts.py, or index in the blog blueprint), that function asks the model for posts, the ORM turns it into SQL for SQLite, and a template turns the rows into HTML with status 200. Each track follows that path in detail later, for example in the Django request and login flow.

The first review: who can write a post?

Clicking around shows you that the blog works. Reading the code tells you what it actually allows. The first question is the write page.

Guard on the write routeVisitorPlain user
Django@login_required302 to the login page, with next setcan write, post saved
FastAPIuser=Depends(require_admin)401 Not authenticated403 Not authorized
Flask@login_required and @admin_required302 to the login page, with next set403

Django's login_required checks one thing: is someone logged in. It doesn't check who. So a brand new plain user can write a post, and it lands on the home page next to the admin's. Is that a bug? Not here. The Django prompt said anyone can register and write, so the code does what was asked. If only staff should write, that's one more check in the view, and you'd say so in the prompt. Review against what you asked, not against what you assumed.

FastAPI and Flask check two things. Here is the FastAPI guard from app/auth.py:

def require_admin(request: Request, db: Session = Depends(get_db)):
    user = require_auth(request, db)
    if not user.is_admin:
        raise HTTPException(
            status_code=status.HTTP_403_FORBIDDEN,
            detail="Not authorized"
        )
    return user

And the decorator the Flask agent wrote itself, at the top of app/routes/admin.py:

def admin_required(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if not current_user.is_authenticated:
            abort(403)
        if not current_user.is_admin(current_app.config['ADMIN_EMAIL']):
            abort(403)
        return f(*args, **kwargs)
    return decorated_function

Both guards work. A plain user gets 403 on the write page, and in the FastAPI run, sending the form directly got the same 403. So the next question is a different one: how does someone become the admin in the first place?

Admin by email

In the FastAPI blog, the register route in app/routes/auth.py (line 47 in this project) decides it:

    # Create user
    is_admin = email == ADMIN_EMAIL
    hashed_password = get_password_hash(password)

In the Flask blog, it's the model method itself (app/models.py, line 23):

    def is_admin(self, admin_email):
        return self.email == admin_email

So if your email matches the ADMIN_EMAIL value in .env, you are the admin. That's the whole check. No email is sent and nothing is confirmed.

The lectures proved it. On a fresh FastAPI database, a newcomer who registered with that address got a 303, is_admin was True, and the write page let them publish. In Flask, the agent had left a delete_admin.py script; running it removed the admin with every post and comment (users went from 5 to 4, posts from 10 to 0), and then a newcomer registered with the admin address and opened the dashboard and the write page with 200. The seeded databases were only safe because the seed script took the address first.

The code does what we asked, but not what we meant. The fix is one line to the agent: create the admin from a setup script (or keep an admin flag in the database set by a setup script), never from the public register form. Then read the diff it makes.

The rest of the first review

Read the project file by file, the same way you read a diff. Each track turned up its own list:

Django

  • Migration 0002 adds an excerpt and a featured image to Post, and 0003 removes them again. The agent changed its mind halfway. Harmless, but ask it to tidy up.
  • We asked for an editor, and the form gives a plain text box with the id editor. That request isn't finished.
  • create_sample_posts creates a user with a known password: fine for testing, never on a server people use.
  • requirements.txt only says Django 6.0.4 or newer, and the run used 6.1.3. Pin the version you tested.

FastAPI

  • create_access_token and a function that reads a JWT sit in app/auth.py, and nothing calls either. The routes keep the user id in the session instead, and python-jose is in the requirements only for that code. Ask the agent to remove it or explain it.
  • datetime.utcnow is deprecated in this Python and prints a warning. The models use it four times and the token code twice.
  • All thirteen routes are async def, but the database session underneath is the regular, blocking kind. The track measures what that costs in How a Request and a Login Flow Through a FastAPI Blog.

Flask

  • routes/auth.py redirects to next from the address bar without checking where it points. Logging in with next set to another website landed there. Ask the agent to follow next only to the blog's own pages.
  • The register form only says the password is required, so a one-character password went through. Ask for a minimum length.
  • The .env file sets a short, fixed SECRET_KEY, config.py has a fallback key in plain text, and no .gitignore keeps the file out of a commit. That key signs the session cookie, so ask for a long random key kept out of the code.
  • main.py runs with debug=True. Fine on your machine, but the debugger puts a Python console on error pages, so never ship it.
  • The editor, SimpleMDE, loads from a link that says latest. In a reviewed copy, pinning version 1.11.2 kept both editor pages working.

And one habit for every track: when the agent's code crashes, pasting the error back is fine, but read the change it makes before you keep it. You'd find none of this by clicking around the site. You find it by reading the code.

Common mistakes

  • Approving the plan without reading it. The plan is the cheapest place to catch a wrong package or a missing feature.
  • Reviewing only the pages. The pages looked fine in all three tracks. The admin-by-email hole, the open redirect and the unused token code are only visible in the files.
  • Reading "logged in" as "allowed". login_required means logged in, not allowed. Check what the guard actually compares.
  • Asking for everything in one prompt. Short follow-ups, one at a time, are easier to review.

Quick recap

StepWhat you do
PromptRole, Context, Task, Format, with "plan first and wait for my OK"
PlanCheck shape, data, stack and anything missing; ask for a new plan in one line if needed
RunRun the commands yourself and watch the first 200
ReviewWho can write (the guard) and who becomes admin (the email check), then the rest file by file

Try it yourself

Log in as one of your test users, leave a comment on a post, and then find that comment again: in the Django admin, or by reopening the post in FastAPI or Flask. Then write the one-line prompt that moves admin creation into a setup script, and read the diff before you keep it.

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 · 8 of 10

Previous
One Blog, Three Frameworks: Routing, Models, Templates and Layout in Django, FastAPI and Flask
Next post
Handing a Figma Design to an AI Agent: Compare the Files, Then Review the Change

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

  • From prompt to review in six steps
  • An empty folder and plan mode
  • The master prompt
  • One database file
  • Reading the plan
  • What the agents built
  • The models
  • Running it ourselves
  • The first review: who can write a post?
  • Admin by email
  • The rest of the first review
  • Django
  • FastAPI
  • Flask
  • Common mistakes
  • 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.