简体   繁体   English

在Django随附的.html页面中从POST获取

[英]Getting from POST in included .html page in Django

I am trying to get the POST values of an .html page that has included pages via {% include %} in Django. 我正在尝试获取通过Django中的{%include%}包含页面的.html页面的POST值。 However, it returns only the POST from the initial html page. 但是,它仅从初始html页面返回POST。

My inner html that is included has the snippet of code: 我包含的内部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 %}

And my outer HTML file has a snippet: 我的外部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>

The everything that shows in post is in the inputs of the second snippet. 帖子中显示的所有内容都在第二个片段的输入中。 But the parameters I want for the first snippet are not included when I use request.POST for all of the POST values. 但是,当我对所有POST值使用request.POST时,不包括我想要的第一个代码片段的参数。

Any help would be greatly appreciated in explaining why I am not getting the values from the included page and finding a possible solution. 在解释为什么我没有从包含的页面中获取值并找到可能的解决方案时,我们将不胜感激。 Thanks! 谢谢!

In HTML, only the fields in the form element that contain the submit button are included in the POST. 在HTML中,POST中仅包含form元素中包含Submit按钮的字段。 the fields in your second file don't seem to be in any form at all, so they will never be posted. 您第二个文件中的字段似乎根本没有任何form ,因此它们永远不会被发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM