本文整理匯總了Python中django.contrib.messages.api.get_messages方法的典型用法代碼示例。如果您正苦於以下問題:Python api.get_messages方法的具體用法?Python api.get_messages怎麽用?Python api.get_messages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.messages.api
的用法示例。
在下文中一共展示了api.get_messages方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: messages
# 需要導入模塊: from django.contrib.messages import api [as 別名]
# 或者: from django.contrib.messages.api import get_messages [as 別名]
def messages(request):
"""
Returns a lazy 'messages' context variable.
"""
return {
'messages': get_messages(request),
'DEFAULT_MESSAGE_LEVELS': DEFAULT_LEVELS,
}
示例2: messages
# 需要導入模塊: from django.contrib.messages import api [as 別名]
# 或者: from django.contrib.messages.api import get_messages [as 別名]
def messages(request):
"""
Return a lazy 'messages' context variable as well as
'DEFAULT_MESSAGE_LEVELS'.
"""
return {
'messages': get_messages(request),
'DEFAULT_MESSAGE_LEVELS': DEFAULT_LEVELS,
}
示例3: get_messages
# 需要導入模塊: from django.contrib.messages import api [as 別名]
# 或者: from django.contrib.messages.api import get_messages [as 別名]
def get_messages(request=None, user=None):
assert bool(request) != bool(user), "Pass exactly one of request or user"
_nonlocal = (user,)
def fetch():
messages = []
(user,) = _nonlocal
if request is not None:
messages.extend(api.get_messages(request))
if request.session.get(SESSION_KEY) and request.user.is_authenticated:
user = request.user
if user is not None:
from user_messages.models import Message
user_messages = Message.objects.filter(
user=user, delivered_at__isnull=True
).order_by("pk")
messages.extend(user_messages)
if any(m.deliver_once for m in user_messages):
user_messages.filter(deliver_once=True).update(
delivered_at=timezone.now()
)
return messages
return SimpleLazyObject(fetch)
示例4: render_to_response
# 需要導入模塊: from django.contrib.messages import api [as 別名]
# 或者: from django.contrib.messages.api import get_messages [as 別名]
def render_to_response(self, context, **response_kwargs):
if self.has_snippet():
extra_content = response_kwargs['extra_content'] = response_kwargs.get('extra_content', {})
extra_content_messages = {}
for message in get_messages(self.request):
extra_content_messages[message.tags] = force_text(message)
if extra_content_messages:
extra_content['messages'] = extra_content_messages
return super().render_to_response(context, **response_kwargs)