2017-01-20 21 views
0

長すぎる文字を埋めて切り取りたい。だから、私はstringformatを使いました。この例では、文字列を10文字にし、必要に応じてパディングを追加します。私はこのコードを私のdjangoテンプレートに持っています。djangoテンプレートの文字列書式

{{ "my too long or too short string"|stringformat:":10" }} 

しかし、djangoは何も出力しません。で、エージェントbulit truncatecharsテンプレートタグ

{{ "my too long or too short string"|truncatechars:10 }} 
+0

使用は、あなたが[カスタムテンプレートフィルタ](https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/を作成することを検討していました

答えて

0
)?
+0

これはcharを切り捨てますが、文字列が短すぎると埋め込みが必要な場合もあります –