1
저는 장고를 처음 접했고 필사적으로 렌더링 할 사전 객체 집합을 얻을 수없는 이유를 알아 내려고했습니다. 다음은 템플릿의 코드 조각입니다 - 디버깅을위한 몇 가지 pprints으로 : - 그 REQID 및 주어진장고는 왜 내 사전을 좋아하지 않습니까?
req.requirement_id: u'man_keephead'
reqid: u'man_keephead'
e_quals: {u'man_keephead': [<EndorsementQual: man_keephead_others>, <EndorsementQual: man_keephead_man>], u'man_trustself': [<EndorsementQual: man_trustself_self>], u'man_waiting': [<EndorsementQual: man_waiting_other>]}
e_quals.reqid: ''
내가 정말 좋아 보인다
<ul>
{% with req.requirement_id as reqid %}
req.requirement_id: {{ req.requirement_id|pprint }}<br />
reqid: {{ reqid|pprint }}<br />
e_quals: {{ e_quals|pprint }}<br />
e_quals.reqid: {{ e_quals.reqid|pprint }}<br />
{% for qual in e_quals.reqid %}
qual.qual_type: {{ qual.qual_type }}
{% if qual.qual_type == "self" %}
<li>Only self-endorsements.</li>
{% endif %}
{% if qual.qual_type == "other" %}
<li>No self-endoresements.</li>
{% endif %}
{% if qual.qual_type == "hasa" %}
<li>Endorser must hold an active {{ qual.qual_data }} badge.</li>
{% endif %}
{% endfor %}
{% endwith %}
</ul>
그리고 여기에 내가 출력으로 무엇을 얻을 e_quals 딕셔너리, e_quals.reqid는 객체 목록을 생성해야합니다. 내가 뭘 놓쳤는 지 모르겠다.
좋은 깨끗한 솔루션을! @alex django를 처음 사용하는 사람이라면이 코드를 어디에 넣을 지 알 것입니다. http://docs.djangoproject.com/en/1.2/howto/custom-template-tags/ – meshantz
감사합니다! 매우 시원하고 도움이됩니다. 나는 사용자 정의 템플릿 태그를 작성하고 그 방법으로 작업을 끝내지 만,이 방법은 훨씬 깔끔합니다 (그리고 왜 작동하지 않는지 알고 행복합니다!) – Alex