开发者

django- how to check validity of single input field inside multi input form

开发者 https://www.devze.com 2023-01-25 19:43 出处:网络
I have a form with multiple input fields, but only want to use one input from the form.What is the proper way to check field validity and get cleaned data for the on开发者_如何学Ce field?

I have a form with multiple input fields, but only want to use one input from the form. What is the proper way to check field validity and get cleaned data for the on开发者_如何学Ce field?

thanks !


The proper way would probably be to add it to it's own form ;)

But... you can do it like this:

form = SomeForm(request.POST)
field = form.fields['your_field']
data = field.widget.value_from_datadict(form.data, form.files, form.add_prefix('your_field'))
cleaned_data = field.clean(data)
0

精彩评论

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