本文整理汇总了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)