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