本文整理匯總了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)