i'm doing a Django app. i have this form
我正在做一个Django应用程序。我有这个表格
class tipoAtribute(forms.Form):
nombreAtribute = forms.CharField(max_length = 25)
CHOICES = (
('VARCHAR', 'Categorico'),
('FLOAT', 'NUMERICO'))
tipoAtribute = forms.MultipleChoiceField(choices = CHOICES, required=True, widget=forms.Select())
and i show this on a table in the HTML, like this:
我在HTML的表格中显示这个,如下所示:
<table id="atributesTable">
<tr>
<td>
{{ form.nombreAtribute }}
</td>
<td>
{{ form.tipoAtribute }}
</td>
</tr>
i made this Script to add another row in the table with the form inside.
我制作了这个脚本,在表格中添加另一行,里面有表格。
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var table = document.getElementById("atributesTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "{{ form.nombreAtribute }}";
cell2.innerHTML = "{{ form.tipoAtribute }}";
}
but this simple doesn't work and i think is because im not showing appropriately the form in the variable cell1 or cell2. but i don't know how to correct this.
但这个简单不起作用,我认为是因为我没有在变量cell1或cell2中正确显示形式。但我不知道如何纠正这一点。
1 个解决方案
#1
0
The text replacement of {{ form.nombreAtribute }}
might include quotes, which will make this script have syntax errors. View the page source in your browser to see the result of the template replacement. You can have Django escape the quotes by running the value through the addslashes
filter.
{{form.nombreAtribute}}的文本替换可能包含引号,这将使此脚本出现语法错误。在浏览器中查看页面源以查看模板替换的结果。你可以让Django通过addslashes过滤器运行值来转义引号。
cell1.innerHTML = "{{ form.nombreAtribute | addslashes }}";
This may or may not be part of your problem.
这可能是您的问题的一部分,也可能不是。
#1
0
The text replacement of {{ form.nombreAtribute }}
might include quotes, which will make this script have syntax errors. View the page source in your browser to see the result of the template replacement. You can have Django escape the quotes by running the value through the addslashes
filter.
{{form.nombreAtribute}}的文本替换可能包含引号,这将使此脚本出现语法错误。在浏览器中查看页面源以查看模板替换的结果。你可以让Django通过addslashes过滤器运行值来转义引号。
cell1.innerHTML = "{{ form.nombreAtribute | addslashes }}";
This may or may not be part of your problem.
这可能是您的问题的一部分,也可能不是。