當前位置: 首頁>>代碼示例>>Python>>正文


Python ip.get_real_ip方法代碼示例

本文整理匯總了Python中ipware.ip.get_real_ip方法的典型用法代碼示例。如果您正苦於以下問題:Python ip.get_real_ip方法的具體用法?Python ip.get_real_ip怎麽用?Python ip.get_real_ip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ipware.ip的用法示例。


在下文中一共展示了ip.get_real_ip方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_ip

# 需要導入模塊: from ipware import ip [as 別名]
# 或者: from ipware.ip import get_real_ip [as 別名]
def get_ip(request):
    try:
        from ipware.ip import get_real_ip

        ip = get_real_ip(request)
        if ip is not None:
            return ip.strip()
    except ImportError:
        pass

    return request.META['REMOTE_ADDR'].split(',')[-1].strip() 
開發者ID:LPgenerator,項目名稱:django-db-mailer,代碼行數:13,代碼來源:utils.py

示例2: __init__

# 需要導入模塊: from ipware import ip [as 別名]
# 或者: from ipware.ip import get_real_ip [as 別名]
def __init__(self, poll, request=None, data=None, **kwargs):
        super(VoteForm, self).__init__(data, **kwargs)
        self.poll = poll
        self.request = request
        self.fields['question'].queryset = poll.questions.all()
        if request:
            self.ip = get_real_ip(self.request) or get_ip(self.request) 
開發者ID:neon-jungle,項目名稱:wagtailpolls,代碼行數:9,代碼來源:forms.py

示例3: process_request

# 需要導入模塊: from ipware import ip [as 別名]
# 或者: from ipware.ip import get_real_ip [as 別名]
def process_request(self, request):
        """Process a request"""
        ip_address = get_real_ip(request)
        if ip_address is not None:
            request.META["HTTP_X_FORWARDED_FOR"] = ip_address
            request.META["REMOTE_ADDR"] = ip_address 
開發者ID:ofa,項目名稱:connect,代碼行數:8,代碼來源:handle_ip.py

示例4: loginview

# 需要導入模塊: from ipware import ip [as 別名]
# 或者: from ipware.ip import get_real_ip [as 別名]
def loginview(request, target):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if not form.is_valid(): # All validation rules pass
            form = LoginForm()
            context = { 'form': form, 'error': 'Invalid form' }
            return scirius_render(request, 'accounts/login.html', context)
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                try:
                    sciriususer = SciriusUser.objects.get(user=user)
                except SciriusUser.DoesNotExist:
                    sciriususer = SciriusUser.objects.create(user=user, timezone = 'UTC')
                    
                if not form.cleaned_data['persistent']:
                    request.session.set_expiry(0)
                logger = logging.getLogger('authentication')
                logger.info("Successful login for '%s' from '%s'", username, get_real_ip(request))
                UserAction.create(
                        action_type='login',
                        user=user,
                        force_insert=True
                )
                return redirect("/" + target)
            else:
                form = LoginForm()
                context = { 'form': form, 'error': 'Disabled account' }
                logger = logging.getLogger('authentication')
                logger.error("Invalid login attempt for disabled account '%s' from '%s'", username, get_real_ip(request))
                return scirius_render(request, 'accounts/login.html', context)
        else:
            form = LoginForm()
            context = { 'form': form, 'error': 'Invalid login' }
            logger = logging.getLogger('authentication')
            logger.error("Invalid login attempt for '%s' from '%s'", username, get_real_ip(request))
            return scirius_render(request, 'accounts/login.html', context)
    else:
        form = LoginForm()
        context = { 'form': form }
        return scirius_render(request, 'accounts/login.html', context) 
開發者ID:StamusNetworks,項目名稱:scirius,代碼行數:46,代碼來源:views.py


注:本文中的ipware.ip.get_real_ip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。