【问题标题】:for loop counter django print in htmlhtml中的for循环计数器django打印
【发布时间】:2011-03-11 08:08:34
【问题描述】:

我想打印包含以下详细信息的患者收据数据:姓名、uid、年龄、身高......电子邮件、药物、剂量..等。

现在我的问题是如何在 html 中打印药物 foreg:medicine-1,medicine-2,medicine-3..n sooo on...。

{% for pmed in meds %}

Medicine

{% endfor %}

但实际上想以这种方式在 html 中打印:我的前半部分正在运行,因为它可以单个数据...例如:

patient name: {{patient.name}} 
uhid: {{patient.uhid}} 
age: {{patient.age}} 
Gender: {{patient.gender}} 
Height: {{patient.height}} 
Weight: {{patient.weight}}

但问题出在药物部分.. 至于一名患者,他们会说 3 种药物......所以我可以在 html 中打印药物部分..好吧,我尝试如下:

{% for pmed in meds %} 
    {{pmed.medicine-forloop.counter}} 
    like for medicine-1:crocin, medicine-2:paraseta 
{% endfor %}

我不明白..你能帮帮我吗?

提前感谢。

【问题讨论】:

    标签: django for-loop counter


    【解决方案1】:

    试试:

    {% for pmed in meds %} 
        Medicine - {{ forloop.counter }} : {{ pmed.medicine }} 
    {% endfor %}
    

    【讨论】:

      【解决方案2】:
      {% for pmed in meds.values %}
          Weight: {{pmed.weight}}
          {% for medicine in pmed.medicines %}
              medince: {{ medicine.name }}
          {% endfor %}
      {% endfor %}
      

      【讨论】:

        猜你喜欢
        • 2010-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多