V
V
vergkir2019-06-04 19:57:46
Django
vergkir, 2019-06-04 19:57:46

How to change an individual field in a form?

I have a problem with the form. The form is normal, not model. In View, I have a function that takes a form (it has 5 fields), calculates the required value, and I need to write this value into one field of the very form that the user sent me, then send this entire form back. So, the question is: "How can I change the value of only one field in the form that I received from the user using the Post method?" I tried, but I can’t access only one field, if the entire form was one field, then we could use .clean ()

form = IpForm(request.POST)
        if form.is_valid():
*выполняется просчет значения*
#тут необходимо записать полученное значение в поле формы с name = 'cidr'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FulTupFul, 2019-06-04
@vergkir

form = IpForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            data['name'] = 'chdir'
            IpForm(data)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question