[Answered ]-DJANGO – change a form value with request.POST?

2πŸ‘

βœ…

The first snippet sets the relationshipId field dynamically, instead of taking it from the POST parameters supplied in the web request.

The second snippet will take that value directly from request.POST, so if your form submits an invalid value, or if no value is given, it will not validate.

The initial argument only applies to unbound forms (see https://docs.djangoproject.com/en/1.5/ref/forms/fields/#initial). You could leave it out here, because you are binding the form to post or request.POST.

Leave a comment