-1

My goal si to storage Ip addresses and make an alert if in the next login the ip address of that person isn't the same. How can I do?

1 Answers1

0

You can make IP field using GenericIPAddressField.

If you don't want to log user's ip history, but just store and compare the latest one, then make the ip field in Customer Model.

class Customer(models.Model):
    ...
    ip_address = models. GenericIPAddressField()

After adding this field, compare and save latest ip in login view. Then you can get what you want.

Plus, if you want to save and compare not only when user log in but also in other cases(thus, in other view functions), it is good to use middleware

mappy
  • 367
  • 5
  • 19
  • The scope of your question is quite wide, so I'm not sure what I'm answering is what you want. If what you are asking is about how to get user'ip in django, then see https://stackoverflow.com/a/4581997/11762177 – mappy Dec 03 '20 at 14:34