What would you think about using a Django form for rendering those hidden fields? That would make the view code much cleaner and the rendering more robust.