Django get_profile() method not working on extended User model

前端 未结 3 1227
心在旅途
心在旅途 2020-12-04 02:27

I have a model in an app named user_profile like so:

from django.db import models
from django.contrib.auth.models import User

class UserProfile         


        
相关标签:
3条回答
  • 2020-12-04 02:50

    Er, you're trying to get the user profile of a UserProfile. I expect you mean to get a User, then call get_profile() on that.

    0 讨论(0)
  • 2020-12-04 02:53

    To anyone else that gets this error by following the old documentation, get_profile() has been depreciated in django 1.7.

    Instead you can just access the userprofile from the user as below..

    u_p = user.userprofile
    

    where userprofile is the name of your UserProfile class

    You can also change to use the newer documentation by clicking on the desired version in the bottom right corner

    0 讨论(0)
  • 2020-12-04 02:53

    I am using Django 1.8 and .userprofile throws an error.

    To get around this since I had profiles setup in Django 1.3, after upgrading to 1.8 I just changed .get_profile() to profile and it works.

    0 讨论(0)
提交回复
热议问题