MAINTENANCE_MODE_IGNORE_IP_ADDRESSES does not work.
Hoshitter1 opened this issue · comments
How does "else:
client_ip_address = get_client_ip_address_func(request)_" (1st one) work?
if settings.MAINTENANCE_MODE_IGNORE_IP_ADDRESSES:
if settings.MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS:
try:
get_client_ip_address_func = import_string(
settings.MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS)
except ImportError:
raise ImproperlyConfigured(
'settings.MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS '
'is not a valid function path.')
else:
client_ip_address = get_client_ip_address_func(request)_
else:
client_ip_address = get_client_ip_address(request)
for ip_address in settings.MAINTENANCE_MODE_IGNORE_IP_ADDRESSES:
ip_address_re = re.compile(ip_address)
if ip_address_re.match(client_ip_address):
return False
Apart from this, Ive tried to use MAINTENANCE_MODE_IGNORE_IP_ADDRESSES in several ways but none of them worked even though other options worked properly. Just for the record I've put
this MAINTENANCE_MODE_IGNORE_IP_ADDRESSES = ("my_ip_here") by referring to http://www.myglobalip.com/ this website. Is there any common errors with this function? Thank you!
@Hoshitter1 what is the value of MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS
?
This is default function to retrieve client ip address:
https://github.com/fabiocaccamo/django-maintenance-mode/blob/master/maintenance_mode/utils.py
For a more advanced usage you should consider to use django-ipware
as suggested in the README.
https://github.com/un33k/django-ipware
Could you write a view that outputs the ip address returned by both libs?
from maintenance_mode.utils import get_client_ip_address
client_ip = get_client_ip_address(request)
from ipware import get_client_ip
client_ip, is_routable = get_client_ip(request)
Thank you for your reply!
-
client_ip = get_client_ip_address(request)
client_ip returns nothing -
client_ip, is_routable = get_client_ip(request)
client_ip returns my ip address as also seen in
http://www.myglobalip.com/
is_routable returns True
@Hoshitter1 could you try also with this function:
https://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django
@Hoshitter1 as you can read, there is not a perfect solution.
I will suggest in the README to use django-ipware
, I could do it by default but I prefere to keep this library dependency-free.
Any suggestion is appreciated.
@fabiocaccamo I installed ipware and wrote MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = 'ipware.ip.get_ip' right before MAINTENANCE_MODE_IGNORE_IP_ADDRESSES in settings.py as you suggested and it worked! Thank you for your support:)