This isn’t Django related, but I think this line is your issue.
You are ending the for and id strings too early with double quotes.
'<li><label for="id_variables_new_"' + index + '">...
will turn in to
<li><label for="id_variables_new_"0">...
Note the extra " before the index.
You should have
'<li><label for="id_variables_new_' + index + '">...
…and the same for the inout.