1

我正在尝试messages framework在我的视图中使用,但它显示以下错误

视图.py

def gcontacts(request):
    error = True
    if request.method == 'POST':
        if request.POST.has_key('wow'):
            error = False
            messages.add_message(request, messages.success, 'Wow key exists !!!!')
        else:
            error = True
    return render_to_response('key_exists.html', {'error':error}, context_instance=RequestContext(request))

错误

Traceback (most recent call last):
  File "/home/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/Envs/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 25, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/virtualenvironment/apps/myapp/views.py", line 33, in gcontacts
    messages.add_message(request, messages.success, 'Wow key exists !!!!')
  File "/home/Envs/local/lib/python2.7/site-packages/django/contrib/messages/api.py", line 20, in add_message
    return request._messages.add(level, message, extra_tags)
  File "/home/Envs/local/lib/python2.7/site-packages/django/contrib/messages/storage/base.py", line 153, in add
    level = int(level)
TypeError: int() argument must be a string or a number, not 'function'

谁能让我知道我在上面的代码中做错了什么?

4

1 回答 1

3

k done 犯了一个小错误,

实际上messages.success应该是messages.SUCCESS,并且有效!!!!

于 2013-08-19T13:10:07.627 回答