本文整理汇总了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()
示例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)
示例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
示例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)