user1328021
user1328021

Reputation: 9840

Just upgraded to Django 1.4 and getting error with messages

I just upgraded to Django 1.4 and it has broken a couple things including messaging.

Here's the error I get when trying to change a avatar:

'User' object has no attribute 'message_set'
Exception Location: /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185

Traceback:

File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  20.                 return view_func(request, *args, **kwargs)
File "/Users/nb/Desktop/spicestore/apps/avatar/views.py" in change
  76.             request.user.message_set.create(
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py" in inner
  185.         return func(self._wrapped, *args)

Exception Type: AttributeError at /avatar/change/
Exception Value: 'User' object has no attribute 'message_set'

Also, messaging no longer works on the site. What are the changes in Django 1.4 that could be causing this and has anyone overcome a similar issue?

Upvotes: 3

Views: 1855

Answers (4)

Robin
Robin

Reputation: 5486

Add

from django.contrib import messages

And then

def foo(request):
    messages.add_message(request, messages.INFO, "Your message.")

Upvotes: 4

nu everest
nu everest

Reputation: 10249

From Django 1.4 docs To enable message functionality, in settings.py do the following:

Edit the MIDDLEWARE_CLASSES setting and make sure it contains

'django.contrib.messages.middleware.MessageMiddleware'

If you are using a storage backend that relies on sessions (the default), django.contrib.sessions.middleware.SessionMiddleware must be enabled and appear before MessageMiddleware in your MIDDLEWARE_CLASSES.

Edit the TEMPLATE_CONTEXT_PROCESSORS setting and make sure it contains

'django.contrib.messages.context_processors.messages'

Add 'django.contrib.messages' to your INSTALLED_APPS setting

As far as django-avatar is concerned. Use the master files found here: https://github.com/chadpaulson/django-avatar/tree/master/avatar

Upvotes: 0

Alasdair
Alasdair

Reputation: 308839

Django introduced a messages app in 1.2 (release notes), and deprecated the old user messages API.

In Django 1.4, the old message_set API has been removed completely, so you'll have to update your code. If you follow the messages docs, you should find it pretty straight forward.

Upvotes: 6

Williams
Williams

Reputation: 4318

What is in your INSTALLED_APPS in your settings.py?

Do you have 'django.contrib.messages', included there?

Something like:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    ...

Upvotes: 0

Related Questions