import re import random import string def remove_html_tags(text): """Remove html tags from a string""" clean = re.compile('<.*?>') return re.sub(clean, '', text) def get_random_int_value(length = 6): return ''.join(list(map(lambda x: str(random.randint(1,9)), list(range(length))))) def get_random_string(length = 8): return ''.join(random.choices(string.ascii_uppercase + string.digits + string.ascii_lowercase, k=length)) def generate_encryption_key(length = 32): return get_random_string(length) def get_ip_address(request): """ use requestobject to fetch client machine's IP Address """ x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', None) if x_forwarded_for: ip = x_forwarded_for.split(',')[0] else: ip = request.META.get('REMOTE_ADDR') ### Real IP address of client Machine return ip