class Middleware:
def process_request(self, request):
#ipreq(self)
ip = request.META['HTTP_X_FORWARDED_FOR']
make_entry(ip)
def make_entry(self, ip):
p = Logging_protocol.objects.create(proto = ip)
p.save()
this is the code in my middleware class. the issue is its making two entries in table when logging in and also on logging out. I want to record IP once when the user logs inn. It also makes entry when the page is loaded from particular IP
Note that middleware operates on every request. Accordingly, the code you should will record every request, not just logins/logouts.
You might like to look at the events framework to respond only to logins and logouts.
In addition, you should probably use new-style classes.