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?
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
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.
| Part | What it says |
|---|---|
| Role | You're a senior FastAPI developer who explains each step. |
| Context | The 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. |
| Task | Build a blog where the admin creates, edits and deletes posts with a free rich text editor, and anyone can register and comment. |
| Format | Plan 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:
- 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)? - The data. Users, posts and comments, and does every post belong to an author?
- The stack. The login you asked for, SQLite, and no extra packages you didn't ask for.
- 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
blogprojectpackage with settings and the main URLs, ablogapp with models, views, urls, forms and admin, a templates folder, and a management command calledcreate_sample_poststhat nobody asked for. Its migrations folder has three files, not one. - FastAPI: an
apppackage withmain.py,database.py,models.py,schemas.pyand anauth.py, plus aroutesfolder withauth.py,posts.pyandcomments.py. So there are two files calledauth.py. The first build crashed; the error was pasted back, and sample posts were asked for at the same time, which is whereseed_data.pycame from. - Flask: an app factory,
create_app, inapp/__init__.py, three blueprints (auth, blog, admin), aconfig.py, a seed script and two small admin scripts. The requirements file is spelledrequirments.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:
| Setup | Start | Sample data | |
|---|---|---|---|
| Django | python manage.py migrate (Django's tables, then the blog's three migrations) | python manage.py runserver | create_sample_posts: a test admin and 6 posts |
| FastAPI | create_all builds the tables when the app starts | uvicorn app.main:app on port 8000 | python seed_data.py: an admin, a regular user, 5 posts, 3 comments |
| Flask | uv venv, then uv pip install -r requirments.txt (19 packages, Flask 3.1.3) | python main.py, debug mode, port 5000 | python 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 route | Visitor | Plain user | |
|---|---|---|---|
| Django | @login_required | 302 to the login page, with next set | can write, post saved |
| FastAPI | user=Depends(require_admin) | 401 Not authenticated | 403 Not authorized |
| Flask | @login_required and @admin_required | 302 to the login page, with next set | 403 |
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
0002adds an excerpt and a featured image to Post, and0003removes 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_postscreates a user with a known password: fine for testing, never on a server people use.requirements.txtonly says Django 6.0.4 or newer, and the run used 6.1.3. Pin the version you tested.
FastAPI
create_access_tokenand a function that reads a JWT sit inapp/auth.py, and nothing calls either. The routes keep the user id in the session instead, andpython-joseis in the requirements only for that code. Ask the agent to remove it or explain it.datetime.utcnowis 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.pyredirects tonextfrom the address bar without checking where it points. Logging in withnextset to another website landed there. Ask the agent to follownextonly 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
.envfile sets a short, fixedSECRET_KEY,config.pyhas a fallback key in plain text, and no.gitignorekeeps 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.pyruns withdebug=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_requiredmeans 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
| Step | What you do |
|---|---|
| Prompt | Role, Context, Task, Format, with "plan first and wait for my OK" |
| Plan | Check shape, data, stack and anything missing; ask for a new plan in one line if needed |
| Run | Run the commands yourself and watch the first 200 |
| Review | Who 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.
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.
