Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

use python logging to log user ips+time in a file whenever a request comes to the server, this should be done in a custom middleware.

import logging

def foo(request):
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
    else:
        ip = request.META.get('REMOTE_ADDR')
        
    some_logger = logging.getLogger(__name__)
    some_logger.warning('Your log message... IP:' + ip)
Comment

PREVIOUS NEXT
Code Example
Python :: deck of cards exercise in python 
Python :: python if block 
Python :: list data structure in python 
Python :: python list of all definitions in python file 
Python :: how to get unknown wifi password using python 
Python :: handling image files django aws 
Python :: Créer un décorateur python 
Python :: Display complete information about the DataFrame 
Python :: python check vpn ip address 
Python :: Python Tkinter PanedWindow Widget Syntax 
Python :: generate a random string with lowercase uppercase and numbers 
Python :: list of object in python 
Python :: how to use print function in python stack overflow 
Python :: how to get the string between brackets in a string in python 
Python :: How to separate characters, Numbers and Special characters from given string with python 
Python :: geopandas plot raster and vector 
Python :: pandas merge keep one of column copy 
Python :: ValueError: minvalue must be less than or equal to maxvalue 
Python :: hashmap in python 
Python :: Implementing Java-style getters and setters in Python 
Python :: how to assign key and value to hash dictionary in python 
Python :: python Pyramid Patterns half 
Python :: images in pygame 
Python :: the best ide for python 
Python :: una esfera solida de radio 40 cm tiene una carga positiva 
Python :: how to create a cubic function in python 3 
Python :: django template child data in nested loop 
Python :: print greeting in python explication 
Python :: np.modf 
Python :: enregistremen en pythin picklr 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =