Imagine you have an address book card. Normally the fields are displayed as static text, in a specific layout (imagine having multiple phone numbers, emails etc.). When editing it, you want to use the same layout, but with form fields instead of static text. It seems that the normal way of doing this in Django is to use separate views and templates, which forces you to duplicate all of the layout markup (ie, it's not DRY), and to change pages to switch between browsing and editing mode.
It would be nicer if you could switch in and out of editing mode on the fly, using JavaScript to replace the static text with form fields and vice versa, and Ajax to send changes to the server. I'm calling this "live editing", but perhaps there is a better term. At any rate, is there a recommended way of doing this in Django?
I was thinking of rendering, for each field, both a static and an editable version, and using JavaScript to hide and show them as needed. But I also need to update the static fields with new data from the server, and I need to take into account inline forms, and complex fields such as images (where the static display is an <img>
tag, and you have to update the src after an upload). And I might also need to add and remove fields or fieldsets dynamically (again, consider inline formsets).
All in all, it'll take a lot of code. Is there an existing solution for Django, or a recommended approach? Otherwise, which JavaScript framework might be most helpful for this?