1 import os 2 import logging 3 4 class safdView(View): 5 6 def getIPFromDJangoRequest(self, request): 7 logging.basicConfig(filename=os.path.join(os.getcwd(), ‘log.txt‘), level=logging.DEBUG) 8 if ‘HTTP_X_FORWARDED_FOR‘ in request.META: 9 logging.debug (request.META[‘HTTP_X_FORWARDED_FOR‘]) 10 else: 11 logging.debug (request.META[‘REMOTE_ADDR‘])
挺实用的功能,将访问者的ip以及时间记录到log文件中。
原文地址:https://www.cnblogs.com/laogao123/p/9792617.html
时间: 2024-10-10 15:12:56