[Fixed]-Pass an Object through Django Forms

1👍

You’re passing a Python object to the template, where Django attempts to render it to HTML and pass it back in the HTTP post. However, neither HTML nor HTTP have any knowledge of what a Customer object is; all you’d get would be the string representation of the object.

You could fix this by passing the Customer id instead, but there is absolutely no point. You don’t need to pass the Customer to and from the form at all; you successfully get it from the request when you instantiate the form on GET, you can do exactly the same on POST.

Leave a comment