django-bakery icon indicating copy to clipboard operation
django-bakery copied to clipboard

Build fails when I add messages

Open ClaudiuCreanga opened this issue 5 years ago • 2 comments

The site works but when I try to bake it, it throws an error:

AttributeError: 'WSGIRequest' object has no attribute '_messages'

During handling of the above exception, another exception occurred

django.contrib.messages.api.MessageFailure: You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware

This happens because in one of my views I add a message

from django.contrib import messages
messages.add_message(request, messages.INFO, "Hello world.")

I have all the required apps installed and it works when running the site normally:

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

Doesn't bakery support showing messages? The use case is that you want to show messages that are not dynamic (hey, I delivered you this site, but it has these errors and these warnings). Obviously I can do it by storing the messages in a variable and not use the django messages framework. Since they are not dynamic, it isn't much work, but would be nicer to go the django way.

ClaudiuCreanga avatar May 14 '19 16:05 ClaudiuCreanga

I don't know the answer here. I've never used the messages framework.

palewire avatar May 14 '19 17:05 palewire

For anyone finding this later, I wouldn't see how this could work without a server. The Django messages framework either uses sessions for logged in users or cookies. In both cases a server is performing some logic. How would it work for an error message one user sees to be stored in a CDN?

Essentially, messages are dynamic.

cmdlinebeep avatar Sep 08 '21 19:09 cmdlinebeep