title: Django - How get IP of request in a custom receiver?
body: <p>I have following code:</p>
  <pre><code>@receiver(user_logged_in)
  def user_logged_in_callback(sender, request, user, **kwargs):  
      ip = request.META.get('REMOTE_ADDR')
      AuditEntry.objects.create(action='User logged in', ip=ip, username=user.username)
  </code></pre>
  <p>It works great.</p>
  <p>In views.py I have a custom receiver:</p>
  <pre><code>@receiver(pre_save, sender=User)
  def user_updated(sender, **kwargs):
      user = kwargs.get('instance', None)
      ip = request.META['REMOTE_ADDR']
      if user:
          new_password = user.password
          try:
              old_password = User.objects.get(pk=user.pk).password
          except User.DoesNotExist:
              old_password = None
          if new_password != old_password:
              AuditEntry.objects.create(action='Password has changed', ip=&quot;127.0.0.1&quot;, username=user.username)
  </code></pre>
  <p>For sure it falls with &quot;no request found&quot; error.</p>
  <p>I can't figure out how to extract IP.</p>
  <p>Thank you.</p>
  <p>Or maybe I am overengineering my code? All I need is to create AuditEntry with parameters after User model has changed.</p>