0Pricing
Django Academy · Lesson

The Messages Framework

Flash success and error notices to users.

The Messages Framework is a free Django Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Flash Messages Are

After an action you often want a one-time notice like Saved! The messages framework shows it on the next page, then forgets it. ✨

Already Set Up

New projects include the messages app plus its middleware and context processor, so you can start flashing notices right away.

Adding a Message

In a view, call messages.add_message with the request, a level, and your text to queue a notice for the visitor.

from django.contrib import messages
messages.add_message(request, messages.SUCCESS, 'Saved!')

Handy Shortcuts

Skip the level argument with helpers like messages.success. They read clearly and cover the levels you use most often.

messages.success(request, 'Profile updated.')

The Message Levels

Five built-in levels exist: DEBUG, INFO, SUCCESS, WARNING, and ERROR. Each maps to a CSS tag you can style differently.

Warnings and Errors

Use messages.error when something fails so the visitor sees a clear, red-styled notice instead of a silent failure.

messages.error(request, 'Could not delete that item.')

They Survive Redirects

Messages are stored until displayed, so they survive a redirect. That fits the post-then-redirect pattern after a form submit perfectly.

Showing Them in Templates

The context processor exposes a messages variable. Loop over it in your base template so every page can show notices.

{% for m in messages %}
  <li>{{ m }}</li>
{% endfor %}

Styling by Level

Each message carries message.tags, like success or error. Drop that into a class to color notices with your CSS.

<li class="{{ m.tags }}">{{ m }}</li>

Read Once, Then Gone

Iterating the messages variable marks them read. They will not reappear on the next request, which is exactly the flash behavior you want.

Where They Are Stored

By default messages use the FallbackStorage, which tries the cookie first and spills into the session for longer notices.

Quick Check

What happens to a message once a template loops over it?

Recap

You learned the messages framework: add notices with levels, survive redirects, render them in your base template, and they vanish after one view. Cookies versus sessions is next. 🍪

Frequently asked questions

Is the “The Messages Framework” lesson free?

Yes — the full text of “The Messages Framework” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.

What will I learn in “The Messages Framework”?

Flash success and error notices to users. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Django Academy?

No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The Messages Framework” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Django Academy lesson?

Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Session Framework
  2. Reading and Writing request.session
  3. The Messages Framework
  4. Cookies vs Sessions
← Back to Django Academy