开发者

Bypass django form validation on new form instance

开发者 https://www.devze.com 2022-12-29 14:56 出处:网络
I have a situation where we are trying to autofill some form data on the second page of a signup and I was wondering if there\'s a way to bypass the entire form validation when we pass in only a coupl

I have a situation where we are trying to autofill some form data on the second page of a signup and I was wondering if there's a way to bypass the entire form validation when we pass in only a couple of fields?

so we have something like

form = NewForm(request.POST)

Where request.POST only contains some of the fields in NewForm(). 开发者_C百科So the page loads and there is feedback about how some fields are not filled in yet.

This all happens from the GET request of the second page.

Is there a way to do something like...

form = NewForm(request.POST, validate=False) 


If you're passing in initial values, you should use the initial parameter, not data (ie the first positional argument). This does not trigger validation.

form = NewForm(initial=dict_of_field_values)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号