【问题标题】:django: how to get a substring?django:如何获取子字符串?
【发布时间】:2011-03-08 03:10:58
【问题描述】:

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

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

【问题讨论】:

  • 你有一个逗号,你应该有一个冒号来切片

标签: python django satchmo


【解决方案1】:

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

>>> 'foobar'[0:5]
[Out] 'fooba'

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

>>> django.utils.safestring.SafeUnicode('foobar')[0:5]
[Out] 'fooba'

【讨论】:

    猜你喜欢
    • 2013-03-30
    • 1970-01-01
    • 2014-05-25
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多