当前位置: 首页>>代码示例>>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;未经允许,请勿转载。