jinja2 how to remove trailing newline

后端 未结 6 1457
轮回少年
轮回少年 2021-01-31 01:36

I\'m using jinja 2 to output a yaml file but can\'t seem to get rid of a trailing newline and the end of a for loop. Eg the below

 - request:
        path: {{ p         


        
6条回答
  •  醉梦人生
    2021-01-31 02:39

    I found a way to solve this problem:

    - request:
        path: {{ path }}
        headers:
          origin: 'somedomain.com'
          user-agent: 'agent'
          referer: 'some.domain.com'
          authority: 'somedomain.com'
        querystring: >-
          {% for key, value in querystring.items() -%}
          {{ key }}: '{{ value }}'
          {% endfor %}
      response:
        content:
          file: {{ content }}
    
    • >, |: "clip": keep the line feed, remove the trailing blank lines.
    • >-, |=: "strip": remove the line feed, remove the trailing blank lines.
    • >+, |+: "keep": keep the line feed, keep trailing blank lines.

    Thx Steve Bennett's post: In YAML, how do I break a string over multiple lines?

提交回复
热议问题