django:如何获取子字符串?

发布于 2024-10-21 04:21:35 字数 205 浏览 6 评论 0原文

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

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

I was modifying satchmo(a python online store project), but I found that I can't use [0, 5] to get the substring in the model. And I found the type is class 'django.utils.safestring.SafeUnicode' in django string processing.

Does class 'django.utils.safestring.SafeUnicode' support [0, 5] to get the substring as in python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红焚 2024-10-28 04:21:35

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

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

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

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

Slice it.
http://docs.python.org/tutorial/introduction.html

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

Update: sure, why not?

>>> django.utils.safestring.SafeUnicode('foobar')[0:5]
[Out] 'fooba'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文