Add request object as optional input to BaseForm class

80 views
Skip to first unread message

Douglas Mumme

unread,
May 23, 2022, 9:29:03 PM5/23/22
to Django developers (Contributions to Django itself)
Hey all,

I've recently made a ticket to add the request object as an optional input to the BaseForm class so that it will easily input for any form if it's needed.

I found out that something like this has been requested before and resolved as a "won't fix", but I think adding it as an optional input will be an easy way developers can pass it through when needed without having to subclass the Form class.

I think a lot of people need the request object in forms for validation and for queryset filtering and this will make life just a little easier.

I would love to hear everyone's thoughts and if this is a good idea.

Thanks!


Adam Johnson

unread,
May 24, 2022, 4:12:04 AM5/24/22
to Django developers (Contributions to Django itself)
I don't think this is a good idea, it couples forms too tightly to requests. The idea of a form is to take dictionaries of form inputs, and validate those. It shouldn't need the request.

If I write a form class that needs extra things from the request, I write my form class to take just that thing. For example, the current user from request.user.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/cd528f14-322b-4786-986c-82f06172ea4en%40googlegroups.com.

Douglas Mumme

unread,
May 26, 2022, 11:58:14 PM5/26/22
to Django developers (Contributions to Django itself)
Hey Adam, yeah I figured it was most likely a design decision to not incorporate request in forms. Thanks for the feedback!
Reply all
Reply to author
Forward
0 new messages