I am trying to validate a form, such that if IP of user (request.META['REMOTE_ADDR']) is in a table BlockedIPs, it would fail validation. However I don’t have access to request variable in Form. How do I do it? Thanks.
I am trying to validate a form, such that if IP of user (
Share
Make it available to your form by overriding
__init__so it can be passed in during construction (or you could just pass the IP itself):Now you just need to pass the
requestobject as the first argument when initialising the form and your custom validation methods will have access to it throughself.request: