# How to access request.session into the forms.py

**URL:** <https://forum.djangoproject.com/t/how-to-access-request-session-into-the-forms-py/20885>\
**Category:** Forms & APIs\
**Created:** [May 12, 2023, 2:33pm UTC](https://forum.djangoproject.com/t/how-to-access-request-session-into-the-forms-py/20885 "2023-05-12T14:33:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![petersongeiger](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/petersongeiger/32/13016_2.png) [@petersongeiger](https://forum.djangoproject.com/u/petersongeiger)\
**Post date:** [May 12, 2023, 2:33pm UTC](https://forum.djangoproject.com/t/how-to-access-request-session-into-the-forms-py/20885/1 "2023-05-12T14:33:52Z")

</div>

Hi all,

I trying to retrive the request.session values into the forms.py to perform the condition for username class.  
I need to avoid the request.user, disable yourself, but it can disable other users  
Is there any chance to have request.session values here or other solution to manipulate the class in this scenario?!? Thanks!

```auto
<!-- forms.py -->
class CustomUserChangeForm(UserChangeForm):
    class Meta:
        model = CustomUser

    def __init__ (self, *args, **kwargs):
        super(). __init__ (*args, **kwargs)

        for field in self.fields:
            self.fields[field].widget.attrs['class'] = 'form-control'
        
        # trying to do something like this
        if request.session.username == self.instance.username:
            self.fields['is_active'].widget.attrs.update({'class':'form-check-input, 'disabled':True})
        self.fields['is_active'].widget.attrs.update({'class':'form-check-input'})

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 12, 2023, 2:52pm UTC](https://forum.djangoproject.com/t/how-to-access-request-session-into-the-forms-py/20885/2 "2023-05-12T14:52:08Z")

</div>

There was a thread not too long ago about this. Take a look at [Using request.user in Forms.py](https://forum.djangoproject.com/t/using-request-user-in-forms-py/19184) and see if that helps.

---

<div class="post-metadata">

**Author:** ![petersongeiger](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/petersongeiger/32/13016_2.png) [@petersongeiger](https://forum.djangoproject.com/u/petersongeiger)\
**Post date:** [May 12, 2023, 2:59pm UTC](https://forum.djangoproject.com/t/how-to-access-request-session-into-the-forms-py/20885/3 "2023-05-12T14:59:36Z")

</div>

That’s what I’m looking for! I’ll see how it goes. Thanks again!
