Want to split user name in django-nonrel
In my django-nonrel project,all usernames are joined with '_'(underscore). For example, if username is 'guest_test' then I want to split guest and test seperate.I am trying with the following code:
CurrentUser=request.user
myuser=CurrentUser.split('_')
username=myuser.pop(0)
institute=myuser.pop(0)
print username
But its giv开发者_运维百科ing error as:
'User' object has no attribute 'split'.
How to do it?
You're confusing the User
object which has lots of attributes with the username
which is one of those attributes.
CurrentUser
contains a User
object, so you need to get the username
of this User
to then do the split
on. Try:
institute,username = CurrentUser.username.split('_')
You are trying to do a split function on the user object which is meant only for string object. You can do a type cast like this .
CurrentUser=str(request.user)
精彩评论