當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。