Comment

Tonis

Thanks for the post, but all the solutions didn't sit well with me. Applying inital values in the __init__ worked, however on loading the form, it rendered with Errors where there were missing values. Which isn't acceptable, those errors should only show when it's been submitted at least once.

The solution was quite simple actually. The internal logic in the form is to ignore initial values if there is a data struct passed into the form. So just don't pass the request.POST or request.GET data. This can be done with just `form = MyForm(request.GET or None, initial={'name': 'Peter'})`. This way on inital load the form will have the inital values, but not think it's been submiteed so won't have errors about missing values. And will ignore the inital values on following submits as there is data there.

Replies

Peter Bengtsson

Thanks! I haven't looked back much since I implemented my solution. There's definitely a feeling that djangos form framework is very much assuming you'll render HTML and submit it regularly.