Django Forms clean() method - need IP address of client
问题 I am overriding the clean() method on a Django form. I want to have access to the IP address of the client (assuming this is a bound form). If I had a reference to the request object, I could get it easily from META("REMOTE_ADDR"). However, I do not have a reference to the request. Any ideas on how this could be done? 回答1: So give yourself a reference to it. class MyModelForm(forms.ModelForm): def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) super(MyModelForm,