Django / Request and data foundations / Lesson 7
Messages after a form submission
Show short-lived feedback after a redirect and test the message without confusing it with durable state.
On this page
Lesson goals
- Describe message storage and request middleware prerequisites.
- Add and display a message after a successful POST.
- Test feedback, redirects and unchanged state after invalid input.
- Trace configured message storage, middleware, redirect, and template rendering after a form submission.
- Test feedback, durable state, authorization, and safe error handling as separate outcomes.
Choose transient feedback
Django’s messages framework carries short notifications between requests, commonly from a successful form submission to the redirected page. It is not a durable audit log or proof that a business operation completed. Store the authoritative state in the database and use messages to help a user understand the result. Do not put secrets or sensitive object details into a message that might be stored in a cookie or session.
Check the configured stack
The messages application, middleware, context processor and a supported storage backend must be configured for the chosen integration. Session-backed storage depends on session middleware and its ordering. Check the actual project settings rather than assuming that every custom configuration matches the standard project template. The target page must render the messages; adding one to the request does not by itself make it visible to the user.
Add feedback after success
The illustrative view fragment assumes an existing valid form, saved object and named destination. Add a success message only after the intended save succeeds, then redirect to the named route. If the form is invalid, return the form and its errors without creating a success message. For a multi-write operation, define transaction behavior explicitly and avoid claiming success if the enclosing operation later rolls back.
from django.contrib import messages
from django.shortcuts import redirect
if form.is_valid():
form.save()
messages.success(request, 'Saved successfully.')
return redirect('profile')
This fragment requires the surrounding view, form and named route. It does not demonstrate transaction or authorization policy.
Render without weakening escaping
The template fragment loops through available messages and renders the message as ordinary escaped text. Message level tags may help select a style, but ensure the mapping is controlled and accessible. A message disappears according to the storage and retrieval behavior; it is not a persistent inbox. Display failures and field-specific form errors where users can understand how to correct their submission.
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
Ordinary template rendering escapes message text. The surrounding page is responsible for accessible presentation.
Test result and message separately
Use Django’s test client with a synthetic form submission and follow the redirect when verifying the target page. Assert the database result, redirect destination and expected message; also submit invalid data and confirm that no record or success feedback appears. Testing the message alone does not verify the write. Test the configured storage and middleware path rather than relying only on a direct view call.
Separate transient feedback from durable business state
Django's messages framework carries short notifications between requests, often from a successful form POST to the page reached after a redirect. A message tells the user what the application intends to communicate; it is not an audit trail, database record, or independent proof that an operation committed. Define the authoritative write first, then add a success message only after the operation's success boundary. An invalid form should show actionable field errors and must not create a success message or unintended record. A redirect can reduce accidental browser refresh resubmission but is not a server-side idempotency guarantee.
Messages can be stored in a session or cookie depending on the configured backend, so keep passwords, tokens, private document contents, and unnecessary personal details out of them. Use concise safe text and a controlled level such as success or error. The Django 5.2 fragments here assume the stated middleware, storage, routes, templates, and disposable synthetic fixtures. They are illustrative and non-runnable; no database, session service, or browser was contacted. Test the durable record, redirect, and message as three related but distinct outcomes.
Trace message storage through the configured request stack
A working integration depends on the messages application, message middleware, a supported storage backend, and appropriate template context when messages are rendered. Session-backed storage also depends on session middleware and its order relative to message middleware. Check the actual project configuration instead of assuming a custom settings module matches a generated project. The destination template must iterate or otherwise render the messages; adding one to a request does not guarantee that a user sees it. An in-process view call without the relevant middleware can fail or omit the storage behavior entirely.
Message consumption is temporary and follows the selected backend and retrieval behavior. Iterating through the messages matters for clearing them from storage, and concurrent requests or separate browser tabs can complicate which response consumes feedback. Do not promise that each tab receives a private durable notification unless the application explicitly implements that contract. Test the actual configured backend with synthetic requests and a followed redirect, then inspect the stored business record separately. A test helper that only mocks messages.success verifies a call, not the full storage and template path.
Place feedback after the real success boundary
Validate the submitted form and authorize the target operation before making its protected change. If the form is invalid, render it with field or non-field errors and preserve appropriate nonsensitive input for correction; do not enqueue a success message. If persistence fails, return or report the application's safe failure outcome rather than claiming the record was saved. A database exception and a valid empty form are not interchangeable. For multiple related writes, define the transaction owner and what happens if an outer transaction later rolls back.
A message call made before the durable operation finishes can contradict the final state. When a success message must follow a transaction's successful commit, arrange it at a boundary whose timing and response lifecycle have been reviewed for the application; do not assume a generic callback alone solves every outer-transaction or response-storage ordering issue. Test a successful commit and a forced rollback under the real configured request path. Keep the user-facing text generic enough to avoid secrets while still explaining the result or next corrective step.
Render feedback as safe and accessible content
Messages are ordinary text unless a narrow reviewed trust policy says otherwise. Render them with normal Django template escaping rather than marking a user-derived string safe to make formatting appear. Message level tags can be mapped to application-owned styles, but do not treat arbitrary tag text as trusted markup. Provide text that communicates the outcome without depending solely on color, and consider an appropriate status or alert region for the page's accessibility contract. Field-specific form errors should remain connected to their controls rather than being replaced by a vague global success or failure notice.
A stored message may be visible after a later request, so avoid placing passwords, access tokens, full submitted records, or private paths inside it. If a user name or title is included, ensure normal escaping and confirm the recipient is authorized to see that information. A template assertion that text exists is useful but does not prove visual presentation, keyboard focus, or screen-reader announcement. Inspect the composed page and use suitable browser and assistive-technology checks for claims about interaction.
Verify the full configured path and its limits
Build a disposable test matrix for an authorized valid POST, an invalid form, a denied actor, a save failure, a destination that does not render messages, and a synthetic markup-like message. For success, assert the persisted record, redirect destination, and expected feedback after following the redirect. For invalid or denied input, assert no unintended record change and no success feedback. Check secret absence in the message and rendered response. Use distinct requests or fresh fixtures so message consumption in one scenario does not contaminate another.
A Django test client can exercise configured URL resolution, middleware, storage, redirect, and template rendering in process, but its results depend on the selected settings and any shortcuts. It is not a real browser or a production cookie and proxy test. A direct RequestFactory view call does not automatically add sessions or message middleware; use it only with explicitly supplied storage when isolating the view. Record the backend, middleware order, template context, and test data. A successful message assertion is evidence of feedback in that fixture, not proof of durable audit, external delivery, or complete accessibility.
20 worked examples
1. Success after save
Problem: Add a short success message only after a valid synthetic form save.
- The form validates and the stated save completes before the message is added.
- The view then redirects to the named profile route with transient feedback.
if form.is_valid():
form.save()
messages.success(request, 'Saved successfully.')
return redirect('profile')
# Fixture: actor authorized; save commits successfully; message stack configured.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The record is saved and the redirect carries a success message.
Why this result follows: Placing the message after the declared success boundary avoids announcing an invalid or failed save.
2. Invalid form has no success
Problem: Render field errors when the synthetic submission is invalid.
- The bound form fails its required-field rule.
- The success branch is skipped and the invalid form is rendered for correction.
if form.is_valid():
form.save()
messages.success(request, 'Saved successfully.')
return redirect('profile')
return render(request, 'profile/edit.html', {'form': form})
# Fixture: required display_name is missing.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: No success message or new record is produced.
Why this result follows: Branching on form validity keeps successful feedback out of the invalid-input path.
3. Save failure
Problem: Avoid a success notification when the database write raises.
- The write fails before execution reaches messages.success.
- The outer boundary handles the failure under the application’s safe error contract.
if form.is_valid():
form.save() # fixture: raises a controlled database exception
messages.success(request, 'Saved successfully.')
# Reviewed outer error boundary handles the exception.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: No success message is added by this branch.
Why this result follows: A notification after the save cannot be reached when that save raises first.
4. Redirect and stored result
Problem: Test the durable write separately from the redirect.
- The response assertion verifies the first HTTP outcome.
- Reloading the profile verifies the actual stored value independently.
response = client.post('/profile/edit/', {'display_name': 'Mira'})
assert response.status_code == 302
profile.refresh_from_db()
assert profile.display_name == 'Mira'
# Fixture: authorized user; isolated database; valid form.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The expected redirect and saved name are both observed in the fixture.
Why this result follows: A redirect alone does not establish that the intended database change occurred.
5. Follow the redirect
Problem: Verify a success message on the destination page.
- follow=True requests the configured redirect destination in the test client.
- The target template renders the stored synthetic message under the stated stack.
response = client.post('/profile/edit/', {'display_name': 'Mira'}, follow=True)
assertContains(response, 'Saved successfully.')
# Fixture: messages middleware, storage, context processor, and target template configured.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The final response contains Saved successfully.
Why this result follows: The full configured request and rendering path is needed to observe user-visible feedback.
6. Destination omits messages
Problem: Diagnose a saved message that is not visible on the next page.
- The view adds the message to the configured storage.
- The destination template never renders the message collection.
view: messages.success(request, 'Saved successfully.')
redirect target: profile.html
profile.html: does not iterate messages
// Synthetic stack trace; storage and middleware otherwise work.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The record may be saved, but the page shows no notification.
Why this result follows: Storing feedback and presenting it in a destination template are separate steps.
7. Render escaped text
Problem: Keep a markup-like message as text in the destination template.
- The message is an ordinary string and the template uses normal autoescaping.
- Angle brackets are escaped instead of creating an emphasis element.
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
{# Fixture: ordinary message text is '<em>Saved</em>'. #}
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The rendered list item contains <em>Saved</em>.
Why this result follows: Normal template escaping keeps this synthetic message as text rather than trusted markup.
8. Do not include a password
Problem: Return safe feedback for an invalid credential-like field.
- The message provides a generic corrective instruction.
- It excludes the password even though the request contained one.
messages.error(request, 'Please check your input and try again.')
# Fixture: submitted password is synthetic and is not included in the message.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The user sees a safe error without the password.
Why this result follows: Transient message storage and rendering are not appropriate places for credentials submitted by the user.
9. Message is not audit
Problem: Distinguish temporary feedback from durable state after a redirect.
- The profile record is stored independently in the database.
- The message is temporary feedback and can be consumed by rendering.
POST: profile record saved
message: 'Saved successfully.' added
next request: message consumed by template
// Synthetic configured message-storage trace.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The profile remains; the message is not a durable audit record.
Why this result follows: Message lifecycle and authoritative business persistence have different purposes and retention in this workflow.
10. Session middleware prerequisite
Problem: Identify a missing dependency for session-backed message storage.
- The chosen storage expects session support for the request.
- The middleware stack does not provide that prerequisite in the stated configuration.
MIDDLEWARE = [
'django.contrib.messages.middleware.MessageMiddleware',
]
# Fixture: selected message storage requires sessions; SessionMiddleware is absent.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The message integration is misconfigured and must be corrected.
Why this result follows: A session-backed message backend depends on the configured session middleware path for each request.
11. Context processor prerequisite
Problem: Explain why a template cannot see messages under a custom context setup.
- The custom template configuration omits the messages context processor.
- The expected messages variable is not supplied by that configured processor in this fixture.
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {'context_processors': []},
}]
# Fixture: template expects the messages context variable.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: Add the intended context processor or explicitly provide the supported context.
Why this result follows: Message storage and template-context availability are separate configuration responsibilities in the request and rendering path.
12. Message levels
Problem: Choose a controlled level for a successful profile save.
- The success helper assigns the framework’s success level.
- The destination may map that controlled level to an accessible presentation.
messages.success(request, 'Profile saved.')
# Fixture: message framework is configured and the profile save succeeded.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The queued feedback is a success-level message.
Why this result follows: A declared message level communicates the outcome without becoming the durable source of truth.
13. Accessible message list
Problem: Render feedback in a clear text status region.
- The template presents the message as text in a list with a declared status role.
- Normal escaping remains enabled and the page must still be tested with the intended assistive technology.
{% if messages %}
<ul role="status">
{% for message in messages %}<li>{{ message }}</li>{% endfor %}
</ul>
{% endif %}
{# Fixture: one ordinary success message. #}
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The composed page contains a status region with the message.
Why this result follows: Semantic markup provides a reviewable presentation boundary without proving complete accessibility for every user.
14. Invalid field feedback
Problem: Keep a field error connected to its input rather than issuing success.
- The missing name produces a correction message for the specific control.
- The input references the error element and no global success is implied.
<label for="id_name">Name</label>
<input id="id_name" name="name" aria-describedby="name-error">
<p id="name-error">This field is required.</p>
{# Fixture: bound form is invalid. #}
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The page shows the associated name error.
Why this result follows: Actionable field feedback and success messages serve different user outcomes in this form workflow.
15. Transaction rollback boundary
Problem: Avoid promising success for a rolled-back multi-write operation.
- The multi-write operation did not reach its durable success boundary.
- The application must not present the same success feedback as a committed operation.
transaction: update profile and related preference
second write: raises; enclosing transaction rolls back
success message: not added under the declared view contract
// Synthetic transaction trace.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: No success message is returned and both writes remain uncommitted.
Why this result follows: Transient feedback should reflect the actual transaction outcome rather than an intermediate step.
16. Message iteration
Problem: Consume available messages through the configured template path.
- The template iterates the message collection supplied to its context.
- The selected backend handles the message lifecycle for this rendered request.
{% if messages %}
{% for message in messages %}<p>{{ message }}</p>{% endfor %}
{% endif %}
{# Fixture: one success message exists in configured storage. #}
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The page displays the one available message.
Why this result follows: Rendering through the configured storage path is distinct from merely calling a message helper.
17. Two tabs and transient storage
Problem: Avoid assuming a message is a durable per-tab notification.
- The tabs can share browser session or cookie-backed state.
- Which response retrieves a temporary message depends on the configured storage and request timing.
tab A: POST saves profile and queues message
tab B: another request reads the same browser message storage
tab A: follows redirect afterward
// Fixture: shared storage and request ordering are application-dependent.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The message is not guaranteed to be a durable per-tab inbox item.
Why this result follows: Transient request storage has different semantics from a dedicated persistent notification system.
18. RequestFactory needs context
Problem: Identify missing message middleware in a direct view test.
- RequestFactory creates a request but does not run middleware automatically.
- The view cannot be assumed to have the configured messages storage without the test supplying it.
request = RequestFactory().post('/profile/edit/', {'display_name': 'Mira'})
response = edit_profile(request)
# Fixture: no session or message storage is attached by the test.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The direct call does not establish the full message lifecycle.
Why this result follows: A focused view test must explicitly supply dependencies normally attached by middleware.
19. Denied actor
Problem: Reject a protected edit without success feedback or state change.
- Authorization rejects the actor before the protected profile update.
- The response and stored name are checked separately from message absence.
response = client.post('/profile/edit/', {'display_name': 'Changed'})
# Fixture: synthetic actor is denied; original name='Original'.
# Assert denial, no success message, and original database value.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: The request is denied, no success feedback appears, and the name stays Original.
Why this result follows: A success message must not mask a denied operation or an unintended partial write.
20. Message assertion limit
Problem: Classify what a test of visible feedback does and does not prove.
- The assertion observes message text in the final in-process response.
- It does not independently verify the saved record, real browser presentation, or accessibility.
response = client.post('/profile/edit/', {'display_name': 'Mira'}, follow=True)
assertContains(response, 'Saved successfully.')
# Fixture: no database assertion or browser interaction test is included.
Illustrative fragment requiring the stated isolated message stack and fixtures; it has not been executed here.
Expected result: Feedback text is confirmed; persistence and interaction remain unproven.
Why this result follows: Each test conclusion is limited to the response and layers it actually observes.
Common errors and fixes
Success appears after an invalid form
- Why it happens
- The success message was added before validation.
- How to fix it
- Add it only on the successful path.
- Prevent it next time
- Test invalid input and unchanged durable state.
A redirect target shows no message
- Why it happens
- The target template does not render messages or the stack is misconfigured.
- How to fix it
- Check the messages context processor, middleware, storage and template.
- Prevent it next time
- Test a complete request followed by the redirect.
A message is treated as an audit record
- Why it happens
- Temporary feedback was used as persistent evidence.
- How to fix it
- Store the authoritative event or state separately.
- Prevent it next time
- Document message retention and security expectations.
20 practice exercises
1. A save succeeds but the redirected page has no notification. What would you inspect?
Show hint
Trace the message from the success branch through storage to the destination template.
Show worked solution
Check that the view adds a message, the storage and middleware are configured, and the destination renders messages. Follow the redirect in a test and inspect the stored object separately.
Confirm that the view adds the message after the successful save, then inspect the selected storage, messages middleware, session prerequisites, context processor, and destination rendering. Follow the redirect in an isolated client test and verify the saved object separately. A helper call alone does not prove visible feedback.
Check your solution
- The configured message path reaches the destination template.
- The saved object is checked independently.
2. Should an error message contain the user password to help diagnose a failed submission?
Show hint
A transient message can be stored and displayed after the request.
Show worked solution
No. Messages can be carried in session or cookie storage and displayed later. Present a safe actionable error, keep secrets out of the message and use controlled diagnostics without recording credentials.
Do not include a password or token in the message; it may be carried by session or cookie storage and displayed later. Show a safe actionable error and use restricted, sanitized diagnostic categories without credentials. Test with a synthetic secret-like value and assert it is absent from message, response, and logs.
Check your solution
- The message contains no password.
- Controlled diagnostics omit the synthetic secret.
3. A valid profile form saves and redirects. Design a test of record, destination, and feedback.
Show hint
Treat the three outcomes separately.
Show worked solution
Submit a valid synthetic form as an authorized user, assert the named redirect, and reload the profile to verify the saved value. Follow the redirect in a configured client and assert the success message appears on the target page. Document the message backend and middleware used by the test.
Check your solution
- The durable value and redirect are correct.
- The destination renders the expected message.
4. An invalid form receives a success notification. Identify the likely boundary error and test.
Show hint
Success belongs after validation and the write.
Show worked solution
Keep messages.success inside the branch that follows valid input and successful persistence. Submit a synthetic missing required field and assert form errors, no success message, and unchanged database state. Include a valid positive case so an implementation that never displays feedback cannot satisfy the entire suite.
Check your solution
- Invalid input produces no success message.
- The record remains unchanged.
5. A save succeeds but the redirected page has no message. List the configured components to inspect.
Show hint
Storage, middleware, context, and template all participate.
Show worked solution
Check that the view actually adds the message after success, the messages app and middleware are enabled, the selected storage and session prerequisites are correct, and the destination receives and renders messages. Follow the redirect in an isolated client test and verify the stored profile independently.
Check your solution
- The message stack is configured.
- The target page renders the available message.
6. Session-backed message storage is selected but SessionMiddleware is absent. Explain the issue.
Show hint
The storage backend has a prerequisite.
Show worked solution
Session-backed messages require the configured session support and correct middleware arrangement. Add or repair the session middleware according to the Django 5.2 documentation and test the actual request followed by the redirect in a disposable environment. Do not assume a message helper call alone proves the integration works.
Check your solution
- Session support is present for the selected backend.
- The complete redirect path is tested.
7. A custom template backend omits the messages context processor. What symptom and check follow?
Show hint
The template needs access to the collection.
Show worked solution
If the template expects the messages context variable but the configured processor does not supply it, the page may not render the queued feedback. Inspect the backend configuration and target template, then follow a synthetic redirect and assert the message appears. Explicitly supplied supported context is another design choice.
Check your solution
- The context source is identified.
- The destination actually displays the feedback.
8. An error message includes the user password for diagnosis. Explain the safer alternative.
Show hint
Messages may persist in cookies or sessions.
Show worked solution
Never include the password or token in user-facing transient feedback. Show a safe actionable error and use controlled operational diagnostics with a bounded category and no credentials. Test with a synthetic secret-like value and assert that it is absent from the message, response, and logs.
Check your solution
- The message contains no password.
- Diagnostics omit the synthetic secret.
9. A message contains <em>Saved</em> from user-controlled text. Specify safe rendering and an appropriate test.
Show hint
Normal autoescaping should treat it as text.
Show worked solution
Render the ordinary message with {{ message }} without the safe filter or a disabled-autoescape block. Assert that the HTML contains escaped angle brackets and that the DOM does not gain an unintended em element. If rich markup is required, define a separate reviewed sanitization and trust contract.
Check your solution
- The markup-like text remains literal.
- No unintended element is introduced.
10. A green success message is the only signal of an update. Improve its accessibility.
Show hint
Do not rely on color alone.
Show worked solution
Include clear textual feedback in an appropriate semantic status region or other reviewed page pattern, and retain normal escaping. Inspect the composed HTML and use keyboard and assistive-technology testing where appropriate. Keep field-specific errors connected to their inputs rather than replacing them with a generic colored notice.
Check your solution
- The outcome is communicated in text.
- Interaction and announcement behavior are reviewed separately.
11. A profile update writes two rows and the second fails. When may success feedback appear?
Show hint
An intermediate write is not the final success boundary.
Show worked solution
Define the transaction owner and add success feedback only when the intended operation has actually succeeded under the application’s transaction and response lifecycle. Force the second write to fail in a disposable test and assert no committed partial state or success message. Test a full successful commit separately.
Check your solution
- A rollback does not produce success feedback.
- The successful commit has its own positive case.
12. A message appears after POST but the database record was not saved. What should the test add?
Show hint
Feedback is not authoritative state.
Show worked solution
Reload the synthetic profile from the disposable database and assert the intended value after the request, in addition to checking redirect and message. If the write fails, the view must not announce success. Keep an invalid or failed-write case to verify unchanged state and safe error behavior.
Check your solution
- The saved value is asserted independently.
- A failed write does not generate success feedback.
13. Two tabs share a session and one consumes a message first. What must the product avoid assuming?
Show hint
Transient storage is not a durable per-tab inbox.
Show worked solution
Document the selected message backend and request-order behavior instead of promising that every tab receives its own durable copy. If the product requires persistent per-user notifications, design a separate storage and access contract. Test the relevant concurrent or sequential synthetic requests without storing sensitive message content.
Check your solution
- The message is treated as transient.
- A durable notification need has a separate design.
14. A direct RequestFactory view test lacks message storage. What does it not establish?
Show hint
The factory does not run middleware automatically.
Show worked solution
A direct request does not automatically receive session or message middleware, so it cannot prove the configured redirect-and-storage lifecycle unless those dependencies are explicitly supplied. Use the configured test client for the complete path and keep the direct test limited to the view behavior it actually exercises.
Check your solution
- The omitted middleware is identified.
- The configured client path is tested separately.
15. A denied actor submits a valid-looking profile form. Define response, state, and message checks.
Show hint
Authorization remains independent from form validity.
Show worked solution
Send the synthetic request as a denied user, assert the configured denial, reload the profile to confirm unchanged values, and verify that no success message is present. Test an authorized user with the same valid input separately. Do not reveal private profile details in the denial.
Check your solution
- The denied request leaves state unchanged.
- No success feedback appears.
16. A message is stored but disappears before the expected page displays it. How would you investigate?
Show hint
Retrieval and iteration affect transient storage.
Show worked solution
Trace the configured backend and intervening requests, including whether another response iterated the shared message storage before the intended redirect target. Reproduce with synthetic sessions and explicit request order, then decide whether the product needs a separate durable notification system. Avoid logging cookie values or private message text.
Check your solution
- The request and consumption order is reproduced.
- The storage contract is distinguished from a durable inbox.
17. A message helper is mocked and the test passes. What additional integration evidence is needed?
Show hint
A mocked call does not exercise storage or rendering.
Show worked solution
Use the configured Django client to submit the form and follow the redirect through the actual message middleware, storage backend, context processor, and target template. Assert the safe visible text and database result separately. Keep the mock test for its narrow call contract, not as proof of the complete user path.
Check your solution
- The actual configured message path is exercised.
- The durable result is asserted separately.
18. A success message includes a private document path. Design a safer feedback and test.
Show hint
Transient feedback should not expose internal locations.
Show worked solution
Use a concise message such as Document saved without the storage key, absolute path, or temporary URL. Submit a synthetic document and assert the public message and absence of the synthetic path, then verify the authorized record and object separately. Protect any detailed operational diagnostics under the application’s policy.
Check your solution
- The user message contains no private path.
- The authorized record and object are checked independently.
19. A success redirect is followed by an accidental refresh and then a deliberate second POST. Explain the difference.
Show hint
A redirect is not an idempotency guarantee.
Show worked solution
Post-redirect-get can reduce a browser refresh repeating the original form submission, but a separate or concurrent POST can still perform the operation again. Define a stable operation identity or other duplicate-control strategy when the business requires it. Test repeated synthetic requests and the final durable state.
Check your solution
- The redirect follows the success path.
- Repeated writes follow an explicit business rule.
20. A test asserts message text but not its accessible presentation. What additional evidence is useful?
Show hint
Text presence and user interaction are different observations.
Show worked solution
Inspect the composed page for appropriate semantic status markup, readable text, and correct association of field errors, then use suitable keyboard and assistive-technology checks for the intended workflow. State the methods and limitations. A server-side string assertion alone cannot prove that the feedback is perceived or announced.
Check your solution
- The composed feedback markup is reviewed.
- Interaction evidence is recorded separately.
Key takeaways
- Messages are transient user feedback, not the source of truth.
- Test the write, redirect and feedback as separate outcomes.
- A transient message is user feedback, not a durable audit record or proof of a write.
- A success notification must follow the actual successful operation boundary.
- Message text should remain escaped and exclude credentials and unnecessary sensitive data.