Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware

I am new to Django. I am trying to run an app and I need to add a new user to admin. The server is running. When I enter the info fir the new user and hit "save" I get the error below. I am using django-trunk.

MessageFailure at /admin/auth/user/add/
You cannot add messages without installing
django.contrib.messages.middleware.MessageMiddleware

Request Method: POST
Request URL:    http://localhost:8000/admin/auth/user/add/
Django Version: 1.6.dev20130403090717
Exception Type: MessageFailure
Exception Value:    You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware

Any ideas of what might be happening?

like image 668
user1867563 Avatar asked Apr 06 '13 14:04

user1867563


2 Answers

For me the problem was specific to unit testing. It turns out that some middleware won't work in some kinds of unit tests, more info here:

https://code.djangoproject.com/ticket/17971

and here:

Why don't my Django unittests know that MessageMiddleware is installed?

My solution was to just mock out the messages framework for those tests, there may be better solutions (the django test client?)

like image 147
hwjp Avatar answered Sep 21 '22 01:09

hwjp


Check if you have django.contrib.messages in INSTALLED_APPS and django.contrib.messages.middleware.MessageMiddleware in MIDDLEWARE_CLASSES.

like image 35
alecxe Avatar answered Sep 20 '22 01:09

alecxe