當前位置: 首頁>>代碼示例>>Python>>正文


Python api.get_messages方法代碼示例

本文整理匯總了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,
    } 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:10,代碼來源:context_processors.py

示例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,
    } 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:11,代碼來源:context_processors.py

示例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) 
開發者ID:matthiask,項目名稱:django-user-messages,代碼行數:30,代碼來源:api.py

示例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) 
開發者ID:matllubos,項目名稱:django-is-core,代碼行數:11,代碼來源:form_views.py


注:本文中的django.contrib.messages.api.get_messages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。