profile = UserProfile.objects.get(....)
내가 현재 시도하고있는 것은 - 현재 로그인 한 사용자의 프로필을 얻는 것입니다. 괄호 안에 무엇을 넣어야합니까?Django 1-1 관계 방법
profile = UserProfile.objects.get(....)
내가 현재 시도하고있는 것은 - 현재 로그인 한 사용자의 프로필을 얻는 것입니다. 괄호 안에 무엇을 넣어야합니까?Django 1-1 관계 방법
을 할 수 있어야한다 :
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
는당신은 할 수 있어야 다음을 사용하십시오.
def my_view(request):
user = request.user
if not isinstance(user, AnonymousUser):
profile = user.get_profile()
# do something with the profile here
else:
# handle anonymous users
Comon guys, 너무 가혹할 필요가 없습니다 ... 실제로 어떤 사람들은 회색 윤곽선 체크 표시가 당신이 무엇을해야하는지 알지 못합니다.
UserProfile.objects.get(user=request.user)
그러나이 OneToOne
필드가 있다면, 당신은 당신이 패턴이 여기에 설명 따르고 있습니다 가정 request.user.userprofile
http://docs.djangoproject.com/en/dev/topics/db/queries/#one-to-one-relationships
유진 감사합니다, 정확하게 그랬습니다. 미안 해요, 아직도 아주 초보자 ^^ – Yulia