Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#13170 closed (fixed)

messages set_level AttributeError

Reported by: dm Owned by: nobody
Component: Contrib apps Version: master
Severity: Keywords: messages, set_level, get_level
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I have the following views.py file:

from django.contrib import messages
from django.shortcuts import render_to_response
from django.template import RequestContext


def main(request):
    messages.set_level(request, messages.DEBUG)
    messages.success(request, 'yo')
    return render_to_response('main.html',
                              context_instance=RequestContext(request))

When I use this view, I get the following:

AttributeError at /

'module' object has no attribute 'set_level'

Here is the patch to fix this problem:

Index: contrib/messages/api.py
===================================================================
--- contrib/messages/api.py     (revision 12825)
+++ contrib/messages/api.py     (working copy)
@@ -4,6 +4,7 @@
 
 __all__ = (
     'add_message', 'get_messages',
+    'get_level', 'set_level',
     'debug', 'info', 'success', 'warning', 'error',
 )

Attachments (1)

ticket_13170.diff (1.0 KB) - added by tobias 5 years ago.
patch that adds get_level & set_level to all

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Yep, as documented here it should made be available.

comment:2 Changed 5 years ago by tobias

  • Owner changed from nobody to tobias
  • Status changed from new to assigned

Changed 5 years ago by tobias

patch that adds get_level & set_level to all

comment:3 Changed 5 years ago by tobias

  • Owner changed from tobias to nobody
  • Status changed from assigned to new
  • Triage Stage changed from Accepted to Ready for checkin

comment:4 Changed 5 years ago by kmtracey

  • Resolution set to fixed
  • Status changed from new to closed

(In [12826]) Fixed #13170: Make get_level and set_level importable from django.contrib.messages,
as documented. Thanks dm, SmileyChris, tobias.

comment:5 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top