0

I have this class in views.py

class getUserData:
    def get(self, data):
        try:
            if self.user.username:
                user = UserData.objects.get(Username=self.user.username)
        except ObjectDoesNotExist:
            print("Error!")

and..

def CheckUserData(request):
    if not getUserData().get('ddd') 
      dsada

On PyCharm - windows - its all ok. On Ubuntu show me error: getUserData instance has no attribute 'user'

Please help

1
  • 1
    You're not using data in get. Is it intentional? Note that your code seems a bit unusual overall, you might want to explain what you're trying to do in more detail. Commented Apr 29, 2015 at 20:11

2 Answers 2

1

The whole piece of code is unnecessary. self.user is already an instance of User. There's absolutely no point getting that user's username and using that to query the User model again: you'd just get back the exact same data you started with.

Just use self.user directly.

Sign up to request clarification or add additional context in comments.

Comments

0

do this

from django.views import generic
class GetUserData(generic.View):
    def get(self, *args, **kwargs):
        user = self.request.user
        if user.username:
            myuser = UserData.objects.filter(username=user.username)
            if myuser:
                print 'coo'
            else:
                print 'nope'

If the data is coming from Get request then do this:

get_data = self.request.GET  # Parse get set after then blammo

1 Comment

Thanks. Can you make this, but for normal function, not get? I don't understand args, kwargs.. I must use: GetUserData.getData("dsa") - Your code is not work - the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.