from xpinyin import Pinyin
p = Pinyin()
# default splitter is `-`
p.get_pinyin(u"上海")
#'shang-hai'# show tone marks
p.get_pinyin(u"上海", show_tone_marks=True)
#'shàng-hǎi'# remove splitter
print(p.get_pinyin(u"上海", ''))
#'shanghai'# set splitter as whitespace
p.get_pinyin(u"上海", ' ')
#'shang hai'
p.get_initial(u"上")
#'S'
p.get_initials(u"上海")
#'S-H'
p.get_initials(u"上海", u'')
#'SH'
p.get_initials(u"上海", u' ')
#'S H'
以上结束,下面是关于drf的
from rest_framework import permissions
classIsOwnerOrReadOnly(permissions.BasePermission):"""
Object-level permission to only allow owners of an object to edit it.
Assumes the model instance has an `owner` attribute.
"""defhas_object_permission(self, request, view, obj):# Read permissions are allowed to any request,# so we'll always allow GET, HEAD or OPTIONS requests.if request.method in permissions.SAFE_METHODS:
returnTrue# Instance must have an attribute named `owner`.return obj.user == request.user
#判断当前用户有木有权限操作