0

我正在尝试通过 Django 中的 {% include %} 获取包含页面的 .html 页面的 POST 值。但是,它只返回初始 html 页面的 POST。

我包含的内部 html 有代码片段:

div id="edit_parameters"><a href="#{{job.slug}}" data-toggle="collapse">Edit Parameters</a></div>  
<div data-id="{{job.slug}}" id="{{job.slug}}" class="collapse">  
<form class = "form-inline" method="post">
    {% csrf_token %}
    {% for parameter in job.get_object.parameters %}
        <p>             
            <input type="text" class="input-small" name="{{parameter}}" value="" id ="{{parameter}}-input" placeholder="{{parameter}}">

        </p>
    {% endfor %}
<button type="submit" class="btn btn-primary run-job">Submit</button>
</form>
</div>
{% else %}
<div>
No editable parameters for this job.
</div>
{% endif %}

我的外部 HTML 文件有一个片段:

<ul id="available-jobs">
    {% if jobs_same_io_type and jobs_diff_io_type %}<h3> Current Step </h3>
    {% elif jobs_same_io_type %} <h3> Next Step </h3> {% endif %}
    {% for job in jobs_same_io_type %}
            {% include "includes/job_li.html" with add=1 %}
    {% endfor %}
    {% if jobs_diff_io_type %} <h3> Next Step </h3> {% endif %}
    {% for job in jobs_diff_io_type %}
            {% include "includes/job_li.html" with add=1 %}
    {% endfor %}
    {% if not jobs_same_io_type and not jobs_diff_io_type %}
    <li class="full-height">There are no more available jobs.</li>
    {% endif %}
    </ul>
    <fieldset class="submit">
        {% csrf_token %}
        <input type="hidden" name="job_to_run" value="" id="job-to-run" />
        <input type="hidden" name="workflow_jobs" value="" id="ordered-jobs" />
        <input type="hidden" name="job_to_edit" value="" id="job-to-edit" />
        <input type="hidden" name="job_to_add" value="" id="job-to-add" />
        <input type="hidden" name="job_to_remove" value="" id="job-to-remove" />
        <input type="submit" name="done" value="I'm done, start the jobs" id="jobs-ready" />
    </fieldset>

帖子中显示的所有内容都在第二个片段的输入中。但是,当我对所有 POST 值使用 request.POST 时,不包括我想要的第一个片段的参数。

在解释为什么我没有从包含的页面中获取值并找到可能的解决方案时,任何帮助将不胜感激。谢谢!

4

1 回答 1

0

在 HTML 中,只有表单元素中包含提交按钮的字段才会包含在 POST 中。您的第二个文件中的字段似乎根本不存在form,因此它们永远不会被发布。

于 2012-11-11T22:44:46.093 回答