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


Python settings.INTERNAL_IPS属性代码示例

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


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

示例1: process_view

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def process_view(self, request, view_func, view_args, view_kwargs):
        """
        If the request method is HEAD and either the IP is internal or the
        user is a logged-in staff member, quickly return with an x-header
        indicating the view function.  This is used by the documentation module
        to lookup the view function for an arbitrary page.
        """
        assert hasattr(request, 'user'), (
            "The XView middleware requires authentication middleware to be "
            "installed. Edit your MIDDLEWARE_CLASSES setting to insert "
            "'django.contrib.auth.middleware.AuthenticationMiddleware'.")
        if request.method == 'HEAD' and (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or
                                         (request.user.is_active and request.user.is_staff)):
            response = http.HttpResponse()
            response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__)
            return response 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:18,代码来源:middleware.py

示例2: log_exception

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def log_exception(request, exception, tb):
    if sentry_sdk is not None:
        sentry_sdk.capture_exception(exception)
        return

    # Send email to admins with details about exception
    ip_type = (
        request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS
        and "internal"
        or "EXTERNAL"
    )
    msg_args = {
        "ip_type": ip_type,
        "path": request.path,
    }
    subject = "Error (%(ip_type)s IP): %(path)s" % msg_args

    try:
        request_repr = repr(request)
    except:
        request_repr = "Request repr() unavailable"

    msg_args = (str(exception.args[0]), tb, request_repr)
    message = "%s\n\n%s\n\n%s" % msg_args
    mail_admins(subject, message, fail_silently=True) 
开发者ID:evernote,项目名称:zing,代码行数:27,代码来源:errorpages.py

示例3: emit

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def emit(self, record):
        try:
            request = record.request
            subject = '%s (%s IP): %s' % (
                record.levelname,
                ('internal' if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
                 else 'EXTERNAL'),
                record.getMessage()
            )
            filter = get_exception_reporter_filter(request)
            request_repr = '\n{}'.format(force_text(filter.get_request_repr(request)))
        except Exception:
            subject = '%s: %s' % (
                record.levelname,
                record.getMessage()
            )
            request = None
            request_repr = "unavailable"
        subject = self.format_subject(subject)

        if record.exc_info:
            exc_info = record.exc_info
        else:
            exc_info = (None, record.getMessage(), None)

        message = "%s\n\nRequest repr(): %s" % (self.format(record), request_repr)
        reporter = ExceptionReporter(request, is_email=True, *exc_info)
        html_message = reporter.get_traceback_html() if self.include_html else None
        self.send_mail(subject, message, fail_silently=True, html_message=html_message) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:31,代码来源:log.py

示例4: debug

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def debug(request):
    """
    Returns context variables helpful for debugging.
    """
    context_extras = {}
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
        context_extras['debug'] = True
        from django.db import connection
        # Return a lazy reference that computes connection.queries on access,
        # to ensure it contains queries triggered after this function runs.
        context_extras['sql_queries'] = lazy(lambda: connection.queries, list)
    return context_extras 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:14,代码来源:context_processors.py

示例5: emit

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def emit(self, record):
        try:
            request = record.request
            subject = '%s (%s IP): %s' % (
                record.levelname,
                ('internal' if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
                 else 'EXTERNAL'),
                record.getMessage()
            )
        except Exception:
            subject = '%s: %s' % (
                record.levelname,
                record.getMessage()
            )
            request = None
        subject = self.format_subject(subject)

        # Since we add a nicely formatted traceback on our own, create a copy
        # of the log record without the exception data.
        no_exc_record = copy(record)
        no_exc_record.exc_info = None
        no_exc_record.exc_text = None

        if record.exc_info:
            exc_info = record.exc_info
        else:
            exc_info = (None, record.getMessage(), None)

        reporter = ExceptionReporter(request, is_email=True, *exc_info)
        message = "%s\n\n%s" % (self.format(no_exc_record), reporter.get_traceback_text())
        html_message = reporter.get_traceback_html() if self.include_html else None
        self.send_mail(subject, message, fail_silently=True, html_message=html_message) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:34,代码来源:log.py

示例6: debug

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def debug(request):
    """
    Return context variables helpful for debugging.
    """
    context_extras = {}
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
        context_extras['debug'] = True
        from django.db import connections
        # Return a lazy reference that computes connection.queries on access,
        # to ensure it contains queries triggered after this function runs.
        context_extras['sql_queries'] = lazy(
            lambda: list(itertools.chain.from_iterable(connections[x].queries for x in connections)),
            list
        )
    return context_extras 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:17,代码来源:context_processors.py

示例7: emit

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def emit(self, record):
        if os.environ.get('SLACK_HOOK', None):
            slack_message = [f'http status: {record.status_code}', f'timestamp: {timezone.now()}']
            try:
                request = record.request
                subject = '%s (%s IP): %s' % (
                    record.levelname,
                    ('internal' if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS else 'EXTERNAL'),
                    record.getMessage(),
                )
                user_info = f'user_id: {request.user.id or "anonymous (None)"}'
                full_path = f'full path: {record.request.get_full_path()}'
            except Exception:  # pylint: disable=W0703
                subject = '%s: %s' % (record.levelname, record.getMessage())
                request = None
                user_info = None
                full_path = None

            exception_message = f'Exception: {",".join(record.exc_info[1].args)}'

            slack_message.append(subject)
            slack_message.append(exception_message)
            if user_info:
                slack_message.append(user_info)
            if full_path:
                slack_message.append(full_path)

            payload = dict(text='\n'.join(slack_message))
            response = urllib.request.urlopen(  # noqa: S310
                urllib.request.Request(
                    os.environ['SLACK_HOOK'],
                    data=json.dumps(payload).encode('utf8'),
                    headers={'content-type': 'application/json'},
                )
            )
            if response.read().decode('utf8') != 'ok':
                logger.error('Could not post to SLACK!') 
开发者ID:vigo,项目名称:django2-project-template,代码行数:39,代码来源:log.py

示例8: debug

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def debug(request):
    """
    Returns context variables helpful for debugging.
    """
    context_extras = {}
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
        context_extras['debug'] = True
        from django.db import connections
        # Return a lazy reference that computes connection.queries on access,
        # to ensure it contains queries triggered after this function runs.
        context_extras['sql_queries'] = lazy(
            lambda: list(itertools.chain(*[connections[x].queries for x in connections])),
            list
        )
    return context_extras 
开发者ID:Yeah-Kun,项目名称:python,代码行数:17,代码来源:context_processors.py

示例9: emit

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def emit(self, record):
        try:
            request = record.request
            subject = '%s (%s IP): %s' % (
                record.levelname,
                (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
                 and 'internal' or 'EXTERNAL'),
                record.getMessage()
            )
            filter = get_exception_reporter_filter(request)
            request_repr = filter.get_request_repr(request)
        except Exception:
            subject = '%s: %s' % (
                record.levelname,
                record.getMessage()
            )
            request = None
            request_repr = "Request repr() unavailable."
        subject = self.format_subject(subject)

        if record.exc_info:
            exc_info = record.exc_info
            stack_trace = '\n'.join(traceback.format_exception(*record.exc_info))
        else:
            exc_info = (None, record.getMessage(), None)
            stack_trace = 'No stack trace available'

        message = "%s\n\n%s" % (stack_trace, request_repr)
        reporter = ExceptionReporter(request, is_email=True, *exc_info)
        html_message = self.include_html and reporter.get_traceback_html() or None
        mail.mail_admins(subject, message, fail_silently=True, html_message=html_message) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:33,代码来源:log.py

示例10: populate_xheaders

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def populate_xheaders(request, response, model, object_id):
    """
    Adds the "X-Object-Type" and "X-Object-Id" headers to the given
    HttpResponse according to the given model and object_id -- but only if the
    given HttpRequest object has an IP address within the INTERNAL_IPS setting
    or if the request is from a logged in staff member.
    """
    from django.conf import settings
    if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
            or (hasattr(request, 'user') and request.user.is_active
                and request.user.is_staff)):
        response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.object_name.lower())
        response['X-Object-Id'] = str(object_id) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:15,代码来源:xheaders.py

示例11: debug

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def debug(request):
    "Returns context variables helpful for debugging."
    context_extras = {}
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
        context_extras['debug'] = True
        from django.db import connection
        context_extras['sql_queries'] = connection.queries
    return context_extras 
开发者ID:blackye,项目名称:luscan-devel,代码行数:10,代码来源:context_processors.py

示例12: allow_ajax

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def allow_ajax(request):
    """
    Default function to determine whether to show the toolbar on a given page.
    """
    if request.META.get('REMOTE_ADDR', None) not in settings.INTERNAL_IPS:
        return False
    return bool(settings.DEBUG) 
开发者ID:djsutho,项目名称:django-debug-toolbar-request-history,代码行数:9,代码来源:request_history.py

示例13: _show_toolbar

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def _show_toolbar(self, request):
        x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', None)
        if x_forwarded_for:
            remote_addr = x_forwarded_for.split(',')[0].strip()
        else:
            remote_addr = request.META.get('REMOTE_ADDR', None)
        if not remote_addr in settings.INTERNAL_IPS \
            or (request.is_ajax() and \
                not debug_toolbar.urls._PREFIX in request.path) \
                    or not settings.DEBUG:
            return False
        return True 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:14,代码来源:middleware.py

示例14: process_request

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INTERNAL_IPS [as 别名]
def process_request(self, request):
        """
        Check if the current site is in maintenance.
        """

        # First check things that don't require a database access:

        # Allow access if remote ip is in INTERNAL_IPS
        if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
            return None

        # Check if the staff the user is allowed
        if hasattr(request, 'user'):
            if request.user.is_superuser:
                return None

            if not MAINTENANCE_BLOCK_STAFF and request.user.is_staff:
                return None

        # ok let's look at the db
        site = Site.objects.get_current()
        try:
            maintenance = Maintenance.objects.get(site=site)
        except Maintenance.DoesNotExist:
            # Allow access if no matching Maintenance object exists
            return None

        # Allow access if maintenance is not being performed
        if not maintenance.is_being_performed:
            return None

        # Check if a path is explicitly excluded from maintenance mode
        ignored_url_list = set(
            maintenance.ignored_url_patterns() + MAINTENANCE_ADMIN_IGNORED_URLS
        )

        ignored_url_patterns = tuple(
            re.compile(r'{}'.format(url)) for url in ignored_url_list
        )

        request_path = request.path_info.lstrip("/")

        for url in ignored_url_patterns:
            if url.match(request_path):
                return None

        # Otherwise show the user the 503 page
        resolver = resolvers.get_resolver(None)

        resolve = resolver.resolve_error_handler
        callback, param_dict = resolve('503')
        return callback(request, **param_dict) 
开发者ID:alsoicode,项目名称:django-maintenancemode-2,代码行数:54,代码来源:middleware.py


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