Skip to content
Learn Netverks

Lesson

Step 27/36 75% through track

messages-flash

Messages framework

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Messages framework: the syntax, APIs, and habits you need before advancing in Django.

Teams ship Messages framework on every Django codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Messages framework in contexts like: SaaS dashboards, CMS-style products, internal tools, and APIs paired with React or mobile clients.

Write Python 3 in the editor and click Run on server—the dev runner executes your script; Django framework lessons also use local startproject for full MVT (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

The messages framework stores one-time notifications (success, error, info) across redirects—"Article saved!" after POST/redirect/GET pattern.

Usage

from django.contrib import messages

def create_article(request):
    if form.is_valid():
        form.save()
        messages.success(request, "Article saved.")
        return redirect("index")

Template

{% if messages %}
  {% for message in messages %}
    <div class="alert {{ message.tags }}">{{ message }}</div>
  {% endfor %}
{% endif %}

Requires django.contrib.messages in INSTALLED_APPS and MessageMiddleware.

Important interview questions and answers

  1. Q: Why messages with redirect?
    A: PRG pattern (POST-redirect-GET) prevents duplicate submits; messages carry feedback to the next GET.
  2. Q: Message storage backends?
    A: Session storage default; cookie fallback—session is typical.
  3. Q: messages vs template context?
    A: Messages persist one request across redirect; context is immediate to current response.

Self-check

  1. What HTTP pattern pairs well with flash messages?
  2. Which middleware enables messages?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • messages framework?
  • Success level?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump