我正在使用django 1.8。
我有以下输入表单:
<!DOCTYPE html>
<html>
<head>
<h1>Post Requirements</h1>
</head>
<body>
<form action="{% url 'recruiter:create_requirement' %}" method="post">
{% csrf_token %}
{% for i in num_reqs %}
<h2>Requirement {{i}}</h2>
<label for="profession">Profession</label>
<select name="profession">
{% for profession in professions %}
<option value="{{profession.id}}">{{profession.profession}}</option>
{% endfor %}
</select>
<br/>
<label for="sub_profession">Sub Profession</label>
<select name="sub_profession">
{% for sub_profession in sub_professions %}
<option value="{{sub_profession.id}}">{{sub_profession.subprofession}}</option>
{% endfor %}
</select>
<br/>
<label for="title">Title</label>
<input id="title" type="text" name="title">
<br/>
{% endfor %}
<input type="submit" value="Create">
</form>
</body>
</html>在提交表单时,我将获得以下格式的QueryDict:
<QueryDict: {u'profession]': [u'1', u'2'],
u'title': [u'Needed actor for Telugu feature film', u'Needed actor for Tamil ad film'],
u'sub_profession': [u'1', u'2']}>我期望的格式是:
<QueryDict: {u'requirements': [
{u'profession': u'1',
u'title': u'Needed actor for Telugu feature film',
u'sub_profession': u'1'},
{u'profession': u'1',
u'title': u'Needed actor for Tamil ad film',
u'sub_profession': u'2'}
]}>如何修改我的超文本标记语言以获得所需的QueryDict。
发布于 2015-09-21 06:17:44
我不确定修改Html会不会给你带来想要的Querydict。我建议你使用javascript来发布。因此,在这种情况下,您可以根据需要打包数据,最后对结果进行JSONify和post。
https://stackoverflow.com/questions/32666012
复制相似问题