Search code examples
pythondjangosatchmo

django: how to get a substring?


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?


Solution

  • 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'