Friday, March 28, 2014

Re: User Profiles "user.get_profile()" returns 'matching query does not exist.'

try:

except:

it worked
thank you!!

On Saturday, September 20, 2008 9:14:42 PM UTC-4, Paddy Joy wrote:
The error message is telling you that the user has no profile
(Specifically there is no record in the table schedule.profile related
to the user).

Your app needs to take care of creating the user profile, even if it
going to be empty. What I have done in my case is I force the user to
create a profile when they first log on by checking if the profile
exists.

        # Check if logged in user has profile, if not redirect to
create profile
        try:
                profile = request.user.get_profile()
        except:
                return HttpResponseRedirect("/createprofile/")


Paddy

On Sep 21, 8:48 am, mclovin <hanoo...@gmail.com> wrote:
> I have spent about 2 hours on this so far, but havent been able to get
> it right, my model is:
>
> (located in schedule/models.py, stripped down to just the profile)
>
> from django.contrib.auth.models import User
> class profile(models.Model):
>     user = models.ForeignKey(User, unique=True)
>     aim = models.CharField(max_length=100, blank=True)
>     website = models.CharField(max_length=100, blank=True)
>
> and i have this as my setting:
> AUTH_PROFILE_MODULE = 'schedule.profile'
>
> I did a syncdb and it showed the profile successfully being added...
>
> then i did in "python manage.py shell":
> from django.contrib.auth.models import User
> u = User.objects.get(pk=1)
> print u.get_profile().aim
>
> but I get this error:
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "/usr/lib/python2.5/site-packages/django/contrib/auth/
> models.py", line 293, in get_profile
>     self._profile_cache =
> model._default_manager.get(user__id__exact=self.id)
>   File "/usr/lib/python2.5/site-packages/django/db/models/manager.py",
> line 93, in get
>     return self.get_query_set().get(*args, **kwargs)
>   File "/usr/lib/python2.5/site-packages/django/db/models/query.py",
> line 303, in get
>     % self.model._meta.object_name)
> DoesNotExist: profile matching query does not exist.
>
> anyone have any idea what is wrong?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/050e7c6c-8dc0-43dc-a20f-f6e3c7475b6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment