2017-12-06 2 views
0

I는 다음과 같습니다 목록이 있습니다 유니 코드 문자없이 정렬 된 구조의 목록을 렌더링

[(u'Element1', u'Description1', u'Status1), (u'newElement2', u'newDescription2', u'newStatus2), (u'nextElement3', u'nextDescription3', u'nextStatus3), (u'anotherElement4', u'anotherDescription4', u'anotherStatus4)] 

내가 텍스트 파일 목록을 렌더링하기 위해 jinja2 템플릿을 사용하는 ansible 각본을 가지고 있습니다. 템플릿 파일은 다음과 같습니다

{% for item in description | batch(3, ' ') %} 
{% for el in item %} 
{{ el }} 
{% endfor %} 
{% endfor %} 

을하지만이 같이하는 텍스트 파일을 반환

Element1   Description1   Status1 
newElement2  nextDescription2  newStatus2 
nextElement3  nextDescription3  nextStatus3 
anotherElement4 anotherDescription4 anotherDescription4 

: 내가 같이하는 보고서를 원하는 것은

[u'Element1', u'Description1', u'Status1] 
[u'newElement2', u'newDescription2', u'newStatus2] 
[u'nextElement3', u'nextDescription3', u'nextStatus3] 
[u'anotherElement4', u'anotherDescription4', u'anotherStatus4] 

이있다 유니 코드 문자를 제거하고이 방법으로 목록을 렌더링하는 방법이 있습니까?

답변

0

의 서식을 변경할 수 있도록하려면 HTML 테이블을 사용할 수

{% for row in description %} 
{% for cell in row %} 
{{ "%-22s"|format(cell) }} 
{%- endfor %} 

{% endfor %} 

수익률 :

Element1    Description1   Status1 
newElement2   newDescription2  newStatus2 
nextElement3   nextDescription3  nextStatus3 
anotherElement4  anotherDescription4 anotherStatus4 

그러나 동적 패딩을 얻으려면 (열에있는 요소의 최대 길이에 따라) 훨씬 더 복잡한 작업처럼 보입니다 : 으로 대체 할 수 있습니다. 은 변수 일 수 있지만 다른 루프가 필요할 수 있습니다 먼저 길이를 수집합니다.

0

당신은

{% for el in item %} 
    {% for e in el %} 
     {{ e }} 
    {% endfor %} 
{% endfor %} 

을 시도 아니면 예를 들어

+0

이렇게하면 모든 것이 서로 위아래로 나타납니다. 형식 지정 순서를 사용하는 것이 가장 좋습니다. – CEamonn

+0

HTML 테이블 사용 – maxbellec

관련 문제