palewire / django-bakery

A set of helpers for baking your Django site out as flat files
https://palewi.re/docs/django-bakery/
MIT License
405 stars 61 forks source link

Build fails when I add messages #135

Open ClaudiuCreanga opened 5 years ago

ClaudiuCreanga commented 5 years ago

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.

palewire commented 5 years ago

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

cmdlinebeep commented 3 years ago

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.