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


Python base.BaseHandler方法代碼示例

本文整理匯總了Python中django.core.handlers.base.BaseHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python base.BaseHandler方法的具體用法?Python base.BaseHandler怎麽用?Python base.BaseHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.handlers.base的用法示例。


在下文中一共展示了base.BaseHandler方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_middleware_loads_on_PRE_django_1_10s_old_style_middleware

# 需要導入模塊: from django.core.handlers import base [as 別名]
# 或者: from django.core.handlers.base import BaseHandler [as 別名]
def test_middleware_loads_on_PRE_django_1_10s_old_style_middleware(self):
        handler = BaseHandler()
        handler.load_middleware() 
開發者ID:muccg,項目名稱:django-useraudit,代碼行數:5,代碼來源:tests.py

示例2: test_middleware_loads_on_django_1_10s_new_style_middleware

# 需要導入模塊: from django.core.handlers import base [as 別名]
# 或者: from django.core.handlers.base import BaseHandler [as 別名]
def test_middleware_loads_on_django_1_10s_new_style_middleware(self):
        handler = BaseHandler()
        handler.load_middleware() 
開發者ID:muccg,項目名稱:django-useraudit,代碼行數:5,代碼來源:tests.py

示例3: make_preview_request

# 需要導入模塊: from django.core.handlers import base [as 別名]
# 或者: from django.core.handlers.base import BaseHandler [as 別名]
def make_preview_request(self, original_request=None, preview_mode=None, extra_request_attrs=None):
        """
        Simulate a request to this page, by constructing a fake HttpRequest object that is (as far
        as possible) representative of a real request to this page's front-end URL, and invoking
        serve_preview with that request (and the given preview_mode).

        Used for previewing / moderation and any other place where we
        want to display a view of this page in the admin interface without going through the regular
        page routing logic.

        If you pass in a real request object as original_request, additional information (e.g. client IP, cookies)
        will be included in the dummy request.
        """
        dummy_meta = self._get_dummy_headers(original_request)
        request = WSGIRequest(dummy_meta)

        # Add a flag to let middleware know that this is a dummy request.
        request.is_dummy = True

        if extra_request_attrs:
            for k, v in extra_request_attrs.items():
                setattr(request, k, v)

        page = self

        # Build a custom django.core.handlers.BaseHandler subclass that invokes serve_preview as
        # the eventual view function called at the end of the middleware chain, rather than going
        # through the URL resolver
        class Handler(BaseHandler):
            def _get_response(self, request):
                response = page.serve_preview(request, preview_mode)
                if hasattr(response, 'render') and callable(response.render):
                    response = response.render()
                return response

        # Invoke this custom handler.
        handler = Handler()
        handler.load_middleware()
        return handler.get_response(request) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:41,代碼來源:models.py

示例4: get_anonymous_request

# 需要導入模塊: from django.core.handlers import base [as 別名]
# 或者: from django.core.handlers.base import BaseHandler [as 別名]
def get_anonymous_request(leonardo_page):
    """returns inicialized request
    """

    request_factory = RequestFactory()
    request = request_factory.get(
        leonardo_page.get_absolute_url(), data={})
    request.feincms_page = request.leonardo_page = leonardo_page
    request.frontend_editing = False
    request.user = AnonymousUser()

    if not hasattr(request, '_feincms_extra_context'):
        request._feincms_extra_context = {}

    request.path = leonardo_page.get_absolute_url()
    request.frontend_editing = False

    leonardo_page.run_request_processors(request)

    request.LEONARDO_CONFIG = ContextConfig(request)

    handler = BaseHandler()
    handler.load_middleware()

    # Apply request middleware
    for middleware_method in handler._request_middleware:
        try:
            middleware_method(request)
        except:
            pass

    # call processors
    for fn in reversed(list(leonardo_page.request_processors.values())):
        fn(leonardo_page, request)

    return request 
開發者ID:django-leonardo,項目名稱:django-leonardo,代碼行數:38,代碼來源:utils.py

示例5: __init__

# 需要導入模塊: from django.core.handlers import base [as 別名]
# 或者: from django.core.handlers.base import BaseHandler [as 別名]
def __init__(self, *args, **kwargs):
        self.handler = BaseHandler()
        self.handler.load_middleware()

        super().__init__(*args, **kwargs) 
開發者ID:wagtail,項目名稱:wagtail-bakery,代碼行數:7,代碼來源:views.py

示例6: __init__

# 需要導入模塊: from django.core.handlers import base [as 別名]
# 或者: from django.core.handlers.base import BaseHandler [as 別名]
def __init__(self, *args, **kwargs):
        # create django request resolver
        self.handler = BaseHandler()

        # prevent recursive includes
        old = settings.MIDDLEWARE
        name = self.__module__ + '.' + self.__class__.__name__
        settings.MIDDLEWARE = [i for i in settings.MIDDLEWARE if i != name]

        self.handler.load_middleware()

        settings.MIDDLEWARE = old
        super(CommonMiddlewareAppendSlashWithoutRedirect, self).__init__(*args, **kwargs) 
開發者ID:openstax,項目名稱:openstax-cms,代碼行數:15,代碼來源:middleware.py

示例7: build_dummy_request

# 需要導入模塊: from django.core.handlers import base [as 別名]
# 或者: from django.core.handlers.base import BaseHandler [as 別名]
def build_dummy_request(newsitem):
    """
    Construct a HttpRequest object that is, as far as possible,
    representative of ones that would receive this page as a response. Used
    for previewing / moderation and any other place where we want to
    display a view of this page in the admin interface without going
    through the regular page routing logic.
    """
    url = newsitem.full_url
    if url:
        url_info = urlparse(url)
        hostname = url_info.hostname
        path = url_info.path
        port = url_info.port or 80
    else:
        # Cannot determine a URL to this page - cobble one together based on
        # whatever we find in ALLOWED_HOSTS
        try:
            hostname = settings.ALLOWED_HOSTS[0]
        except IndexError:
            hostname = 'localhost'
        path = '/'
        port = 80

    request = WSGIRequest({
        'REQUEST_METHOD': 'GET',
        'PATH_INFO': path,
        'SERVER_NAME': hostname,
        'SERVER_PORT': port,
        'HTTP_HOST': hostname,
        'wsgi.input': StringIO(),
    })

    # Apply middleware to the request - see http://www.mellowmorning.com/2011/04/18/mock-django-request-for-testing/
    handler = BaseHandler()
    handler.load_middleware()
    # call each middleware in turn and throw away any responses that they might return
    if hasattr(handler, '_request_middleware'):
        for middleware_method in handler._request_middleware:
            middleware_method(request)
    else:
        handler.get_response(request)

    return request 
開發者ID:neon-jungle,項目名稱:wagtailnews,代碼行數:46,代碼來源:editor.py


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