0

我刚刚升级到 Django 1.4 并收到以下错误:

'WSGIRequest' object has no attribute 'SUCCESS'

追溯:

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/spicestore/apps/account/views.py" in login
  87.             messages.add_message(request.SUCCESS,

Exception Type: AttributeError at /account/login/
Exception Value: 'WSGIRequest' object has no attribute 'SUCCESS'

有谁知道可能是什么原因造成的?

这是views.py中的实际代码:

 messages.add_message(request.SUCCESS,
        ugettext(u"Successfully logged in as %(user)s.") % {
            "user": user_display(form.user)
        }
4

1 回答 1

0
messages.add_message(request, 
                 messages.SUCCESS, 
                 ugettext(u"Successfully logged in as %(user)s.") % { "user": user_display(form.user) })

或更快:

messages.success(request, 
                 ugettext(u"Successfully logged in as %(user)s.") % { "user": user_display(form.user) })

请参阅: https ://docs.djangoproject.com/en/dev/ref/contrib/messages/#using-messages-in-views-and-templates

于 2013-01-07T11:47:29.597 回答