2012-11-11 41 views
0

我正在試圖通過Django中的{%include%}獲取包含頁面的.html頁面的POST值。但是,它僅從最初的html頁面返回POST。在包含在Django中的.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時,我不想包含第一個片段所需的參數。

任何幫助將不勝感激解釋爲什麼我沒有從包含的頁面獲取值並找到可能的解決方案。謝謝!

+0

HTTP只允許一個帖子。看起來你想立即張貼幾個表格? – RParadox

+0

有沒有辦法從一組特定的「參數」或特定的表單中獲取POST? – user992296

回答

0

在HTML中,POST中只包含表單元素中包含提交按鈕的字段。您的第二個文件中的字段似乎完全不在form之內,因此它們永遠不會被髮布。

+0

問題是隻有第二個文件中的字段顯示在後,而不是第一個文件中的窗體中的東西,但這很奇怪。 – user992296

+0

我想表單標籤位於HTML中不顯示的位。但是,關鍵點仍然是,只有包含您實際點擊的提交按鈕的表單纔會被提交。 –

+0

我也這麼認爲,但是,它現在只提交for循環的第一次迭代。因此,除了字段集中的所有內容外,只有第一個作業參數。也就是說,即使您點擊提交第二個工作,它仍然只提交第一個參數。我想也許這是因爲我的表單缺少唯一的ID,但我添加了這些,問題依然存在。 – user992296