我希望行按 col 对齐,我编写代码:
result.seq_content = 'GCAUCCGGGUUGAGGUAGUAG'
result.vel_bar = '|| |||||| ||| ||| ||'
result.seq_match = 'CG.AGGUUC..UUC.AUC.UC'
<table style="font-family:Courier, monospace;">
<td>
{{ result.seq_content}}
<br>
{{ result.vel_bar}}
<br>
{{ result.seq_match}}
</td>
</tr>
</table>
但是结果是
多个空格变成一个空格。
我用了tag pre,但是A,C,G,U的大小不等于|的大小或空间,所以它失败了。
我更改了代码:
result.seq_content = 'GCAUCCGGGUUGAGGUAGUAG'
result.vel_bar = '|| |||||| ||| ||| ||'
result.seq_match = 'CG.AGGUUC..UUC.AUC.UC'
<table style="font-family:Courier, monospace;">
<tr>
<td>
{{ result.seq_content}}
<br>
{% for e in result.vel_bar %}
{% if e == ' '%}
 
{% else%}
{{ e}}
{% endif%}
{% endfor%}
<br>
{{ result.seq_match}}
</td>
</tr>
</table>
但是 {{ e}} 的大小比 A, C, G, U 大。
那么我怎样才能对齐多个空格,就像这样:
GCAUCCGGGUUGAGGUAGUAG
|| |||||| ||| ||| ||
CG.AGGUUC..UUC.AUC.UC
谢谢! :D
问题已经解决
我把''全部换成了nbsp;,并且取消了自动转义,这是我的代码:
result.vel_bar = result.vel_bal.repalce(' ', ' ')
<td align="left">
{{ result.seq_content }}
{% autoescape false%}
{{ result.vel_bar}}
{% endautoescape %}
{{ result.seq_match }}
</td>
谢谢你的帮助。 :D
最佳答案
首先,使用等宽字体很好。 HTML 将多个空格替换为一个:但您可以将每个空格替换为
result.vel_bar.replaceAll(/\s/, ' ')
这样你的对齐应该是完美的。
关于python - HTML 多空格对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23453815/