当前位置: 首页>>代码示例>>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;未经允许,请勿转载。