如何在django views.py中检索动态创建的字段(在模板中)值

时间:2015-06-09 13:09:38

标签: javascript python django dynamic form-fields

我使用javascript在templates / app_name文件夹中的.html文件中创建了多个动态表单字段。我想在django中的views.py中检索那些动态创建的字段的值。

我的javascript(addInput.js)

var counter = 1;
var limit = 5;
function addInput(divName){

        if(counter == limit){

            alert("You have reached the limit of adding " + counter + " Email Addresses");

        }
        else {

                var newdiv = document.createElement('div');
                newdiv.innerHTML = "<p id = 'remove" + counter + "'>Email Address " + (counter+1) + " : " + "<input id = 'myId" + (counter+1 + "' type = 'text' name ='myInputs[]'></p>";
                document.getElementById(divName).appendChild(newdiv);
                counter++;
                alert(counter + "add");
        }
   }

我的.html(在templates / app_name文件夹中)

<form method="POST" onsubmit = "return validateEmail('dynamicInput');" action = "/fcui/register/">
    <div id = "dynamicInput">
        <p id = 'remove0'>Email Address 1 : <input id = "myId1" type="text" name="myInputs[]"></p>        
    </div>
    <br><br><input type ="button" value= "Add another Email Address" onClick = "addInput('dynamicInput');">
        <input type ="button" value= "Remove Email Address Field " onClick = "removeInput('dynamicInput');">

        <br><br><input type ="submit" value= "Send Invites" > 
        <input type='hidden' name='csrfmiddlewaretoken' value='xyz' />
</form>

我尝试将其检索为:

   print request.POST['myInputs[]']

但它只检索一个值,即最后一个字段值

如何检索所有其他值?我尝试在互联网上搜索这个,但在django上下文中找不到相关内容。请帮忙。我是django的新手。

0 个答案:

没有答案