T
T
tadej2015-08-21 16:07:17
Django
tadej, 2015-08-21 16:07:17

How to add a new variable to request.POST on the server side?

You need to register a user on the site. But not from the registration page, but from another page.
All data comes in POST except for the password (it is not there), and the form validator swears: the password field is required.
It is necessary to add the pass field to the POST.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tplus, 2015-08-22
@tadej

In older versions, you can make a copy of the request:
- or via request.POST = request.POST.copy();
- or through assembly of the request yourself:

qd = QueryDict('', 'mutable')
qd[key] = value
request.POST = qd

In new versions of django, you can directly correct the request:
Well, it's better to pay attention to value - in older versions of django, you may have to pass not value, but [value].

S
sim3x, 2015-08-21
@sim3x

Make a separate form for this case
later

my_form = MyModelForm(request.POST)
my_form.is_valid()
my_model = my_form.save(commit=False)
my_model.pass = 'foo'
my_model.save()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question