Search code examples
pythongoogle-app-enginedjango-nonrel

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 giving error as:

'User' object has no attribute 'split'.

How to do it?


Solution

  • 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('_')