So i saw in this answer:
http://stackoverflow.com/a/11072057/1061426
that someone said:
Change this line:
form = StatementForm(request.POST, initial={'time': d.strftime("%Y-%m-%d %H:%M:%S"), 'user':loggedin_user, 'views':0})For this:
form = StatementForm(initial={'time': d.strftime("%Y-%m-%d %H:%M:%S"),'user':loggedin_user, 'views':0})
What is the difference between including the request.POST and not? Or, more to the point – if value X isn’t set in request.POST, but is included in the initial array, what value of X does the is_valid() method see?
EDIT: I guess what i’m asking is ~ which takes precedence in the above? If request.POST and an initial are added, does the initial value overwrite the request.POST value? Is an “empty” value able to be overwritten?
(In the question i relate to, the author was mistakingly using request.POST to seed the StatementForm when the method was a get, which was causing problems for him. )
initialis an argument used to set the initial value of the form at runtime.Now,
request.POSTis used to bind a form to post data. For example, while submitting a form from browser usingPOSTall the relevant fields would be assigned to theformobject that it can find inrequest.POSTIf X is not set in the form, the value is taken from the initial, if present.
You can read up about initial here