当前位置: 首页>>代码示例>>Python>>正文


Python request.HttpRequest方法代码示例

本文整理汇总了Python中django.http.request.HttpRequest方法的典型用法代码示例。如果您正苦于以下问题:Python request.HttpRequest方法的具体用法?Python request.HttpRequest怎么用?Python request.HttpRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http.request的用法示例。


在下文中一共展示了request.HttpRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_view

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def process_view(
        self,
        request: HttpRequest,
        view_func: Callable,
        view_args: Any,
        view_kwargs: Any,
    ) -> None:
        """Add view_func to the profiler info."""
        # force the creation of a valid session by saving it.
        if (
            hasattr(request, "session")
            and request.session.session_key is None
            and settings.STORE_ANONYMOUS_SESSIONS is True
        ):
            request.session.save()

        if hasattr(view_func, "__name__"):
            request.profiler.view_func_name = view_func.__name__
        else:
            request.profiler.view_func_name = view_func.__class__.__name__ 
开发者ID:yunojuno,项目名称:django-request-profiler,代码行数:22,代码来源:middleware.py

示例2: create

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def create(self, request: HttpRequest, *args, **kwargs) -> Response:
        """
        DRF method for creating a Nomination.

        Called by the Django Rest Framework in response to the corresponding HTTP request.
        """
        for field in request.data:
            if field in self.frozen_on_create:
                raise ValidationError({field: ['This field cannot be set at creation.']})

        user_id = request.data.get("user")
        if Nomination.objects.filter(active=True, user__id=user_id).exists():
            raise ValidationError({'active': ['There can only be one active nomination.']})

        serializer = self.get_serializer(
            data=ChainMap(
                request.data,
                {"active": True}
            )
        )
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers) 
开发者ID:python-discord,项目名称:site,代码行数:26,代码来源:nomination.py

示例3: create

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def create(self, request: HttpRequest) -> Response:
        """
        DRF method for creating a new OffTopicChannelName.

        Called by the Django Rest Framework in response to the corresponding HTTP request.
        """
        if 'name' in request.query_params:
            create_data = {'name': request.query_params['name']}
            serializer = OffTopicChannelNameSerializer(data=create_data)
            serializer.is_valid(raise_exception=True)
            serializer.save()
            return Response(create_data, status=HTTP_201_CREATED)

        else:
            raise ParseError(detail={
                'name': ["This query parameter is required."]
            }) 
开发者ID:python-discord,项目名称:site,代码行数:19,代码来源:off_topic_channel_name.py

示例4: list

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def list(self, request: HttpRequest) -> Response:
        """
        DRF method for listing OffTopicChannelName entries.

        Called by the Django Rest Framework in response to the corresponding HTTP request.
        """
        if 'random_items' in request.query_params:
            param = request.query_params['random_items']
            try:
                random_count = int(param)
            except ValueError:
                raise ParseError(detail={'random_items': ["Must be a valid integer."]})

            if random_count <= 0:
                raise ParseError(detail={
                    'random_items': ["Must be a positive integer."]
                })

            queryset = self.get_queryset().order_by('?')[:random_count]
            serialized = self.serializer_class(queryset, many=True)
            return Response(serialized.data)

        queryset = self.get_queryset()
        serialized = self.serializer_class(queryset, many=True)
        return Response(serialized.data) 
开发者ID:python-discord,项目名称:site,代码行数:27,代码来源:off_topic_channel_name.py

示例5: get_dummy_request

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def get_dummy_request(dc, method=None, user=None, system_user=False):
    """
    Return dummy request object.
    """
    request = HttpRequest()
    request.csrf_processing_done = True
    request.dc = dc

    if method:
        request = set_request_method(request, method, copy_request=False)

    if system_user:
        from api.task.utils import get_system_task_user
        request.user = get_system_task_user()
    elif user:
        request.user = user

    return request 
开发者ID:erigones,项目名称:esdc-ce,代码行数:20,代码来源:request.py

示例6: compile_node_actions

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def compile_node_actions(node, user, request=None, classes=ACTION_CLASSES):
    """Provide :class:`NodeAction` objects for given request.

    :param node: The :class:`Node` that the request pertains to.
    :param user: The :class:`User` making the request.
    :param request: The :class:`HttpRequest` being serviced.  It may be used
        to obtain information about the OAuth token being used.
    :return: An :class:`OrderedDict` mapping applicable actions' display names
        to corresponding :class:`NodeAction` instances.  The dict is ordered
        for consistent display.
    """
    actions = (action_class(node, user, request) for action_class in classes)
    return OrderedDict(
        (action.name, action)
        for action in actions
        if action.is_actionable() and action.is_permitted()
    ) 
开发者ID:maas,项目名称:maas,代码行数:19,代码来源:node_action.py

示例7: test_middleware_no_process_request

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def test_middleware_no_process_request():
    middleware = NPlusOneMiddleware()
    req, resp = HttpRequest(), HttpResponse()
    processed = middleware.process_response(req, resp)
    assert processed is resp 
开发者ID:jmcarp,项目名称:nplusone,代码行数:7,代码来源:tests.py

示例8: render

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def render(self):
        if not self.template_name:
            return None
        try:
            logger.debug("Template name: %s" % self.template_name)
            template = get_template(self.template_name)      
        except TemplateDoesNotExist:
            logger.debug("Template not found: %s" % self.template_name)
            return None
        # TODO: Avoid using a null HttRequest to context processors
        ctx = RequestContext(HttpRequest(), self.ctx)
        return template.render(ctx) 
开发者ID:jlmadurga,项目名称:django-telegram-bot,代码行数:14,代码来源:responses.py

示例9: get_context

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def get_context(self, request: HttpRequest, *args, **kwargs) -> Dict[str, Any]:
        context = super().get_context(request, *args, **kwargs)

        return {**context, "props": self.get_component_data({"request": request})} 
开发者ID:Frojd,项目名称:Wagtail-Pipit,代码行数:6,代码来源:base.py

示例10: serve

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def serve(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
        if self.should_serve_json(request):
            json = self.get_component_data({"request": request})
            return JsonResponse(json)

        return super().serve(request, *args, **kwargs) 
开发者ID:Frojd,项目名称:Wagtail-Pipit,代码行数:8,代码来源:base.py

示例11: should_serve_json

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def should_serve_json(request: HttpRequest) -> bool:
        return (
            request.GET.get("format", None) == "json"
            or request.content_type == "application/json"
        ) 
开发者ID:Frojd,项目名称:Wagtail-Pipit,代码行数:7,代码来源:base.py

示例12: test_with_host

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def test_with_host(self):
        request = HttpRequest()
        request.META = {'HTTP_HOST': 'example.com', 'SERVER_PORT': 80}
        self.assertEqual(Site.find_for_request(request), self.site) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_sites.py

示例13: test_with_unknown_host

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def test_with_unknown_host(self):
        request = HttpRequest()
        request.META = {'HTTP_HOST': 'unknown.com', 'SERVER_PORT': 80}
        self.assertEqual(Site.find_for_request(request), self.default_site) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_sites.py

示例14: test_with_server_name

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def test_with_server_name(self):
        request = HttpRequest()
        request.META = {
            'SERVER_NAME': 'example.com',
            'SERVER_PORT': 80
        }
        self.assertEqual(Site.find_for_request(request), self.site) 
开发者ID:wagtail,项目名称:wagtail,代码行数:9,代码来源:test_sites.py

示例15: test_with_x_forwarded_host

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import HttpRequest [as 别名]
def test_with_x_forwarded_host(self):
        with self.settings(USE_X_FORWARDED_HOST=True):
            request = HttpRequest()
            request.META = {'HTTP_X_FORWARDED_HOST': 'example.com', 'SERVER_PORT': 80}
            self.assertEqual(Site.find_for_request(request), self.site) 
开发者ID:wagtail,项目名称:wagtail,代码行数:7,代码来源:test_sites.py


注:本文中的django.http.request.HttpRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。