Most of the time, I use POST for forms, but using GET is useful when
developing a search form, for example. This is especially true if you
want to paginate your results, because you still have all your
original form variables in the query string.

CBV FormView get_form_kwargs() only populates form_kwargs data if the
request is POST or PUT, which means that a GET form will never have
form.is_valid() == True, even thought the supplied query string may
indeed validate all form fields.

Is this by design, or an oversight?

I'm working around this for now by overriding get_form_kwargs() in my
view like so:

    def get_form_kwargs(self):
        kwargs = {'initial': self.get_initial()}
        if self.request.GET:
            kwargs['data'] = self.request.GET
        return kwargs

If the view is requested with no query string, request.GET will be
empty, and thus kwargs will not have 'data' key. Consequently,
form.is_valid() returns False. If I submit the form though, and the
view is request with a URL query string, kwargs['data'] gets set to
request.GET, and form.is_valid() returns True (if the values satisfy
the various form clean_foo() methods.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to