django:如何获取子字符串?

Bin*_*hen 0 python django satchmo

我正在修改satchmo(一个python在线商店项目),但我发现我无法使用[0, 5]来获取模型中的子字符串。我发现类型是 django 字符串处理中的类“django.utils.safestring.SafeUnicode”。

类 'django.utils.safestring.SafeUnicode' 是否支持 [0, 5] 来获取像在 python 中那样的子字符串?

Yuj*_*ita 5

切片。 http://docs.python.org/tutorial/introduction.html

>>> 'foobar'[0:5]
[Out] 'fooba'
Run Code Online (Sandbox Code Playgroud)

更新:当然,为什么不呢?

>>> django.utils.safestring.SafeUnicode('foobar')[0:5]
[Out] 'fooba'
Run Code Online (Sandbox Code Playgroud)