I would like to say that this code is really bad :
def get_queryset(self):
UserModel = get_user_model()
pk = self.kwargs['pk']
if not pk:
profile = UserModel.objects.filter(pk=self.request.user)
else:
profile = UserModel.objects.filter(pk=self.kwargs['pk'])
return profile
I've also made it few times.
Lets try to fix :
def get_queryset(self) passes nothing to the function and of course
dic self.kwargs[] is not present :
adding args to this one
def get_queryset(self, kwargs):
""" this is more better """
after this I'm proposing add some debugging steps:
# this string be removed after fixing most bug
print self.kwargs
let start do do with our pk : we dont know if this user id is present
in database then try to do this in polite way via exception :
try:
return UserModel.objects.filter(int (pk=self.kwargs['pk']))
except KeyError:
# if pk is not present the we should create it ? Is not it ? I
have not seen this code in your example
If you need more help ask me.
thanks ,
Serge
+380636150445
2012/11/21 David <[email protected]>:
> Hi Patrick
>
> The error exists on this line:
>
> pk = self.kwargs['pk']
>
> KeyError at /accounts/profile/
> 'pk'
> Request Method: GET
> Request URL: http://127.0.0.1:8000/accounts/profile/
> Django Version: 1.5
> Exception Type: KeyError
> Exception Value:
> 'pk'
> Exception Location: C:\Users\DavidWills.DELTAGEM\Django
> Projects\membersarea\accounts\views.py in get_queryset, line 69
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/sAl9k5yrHOsJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.