0
profile = UserProfile.objects.get(....)

私がやろうとしているのは、現在ログインしているユーザーのプロファイルを取得することです。括弧内には何を入れればよいですか?

4

2 に答える 2

2

ここで説明されているパターンに従っていると仮定します。

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
于 2011-02-22T16:53:54.050 に答える
2

一般人、それほど厳しくする必要はありません... 一部の人々は、灰色のアウトラインのチェックマークが押されるべきものであることを実際には知りません.

UserProfile.objects.get(user=request.user) 

しかし、それがフィールドの場合、 http://docs.djangoproject.com/en/dev/topics/db/queries/#one-to-one-relationshipsOneToOneを実行できるはずですrequest.user.userprofile

于 2011-02-22T16:51:16.303 に答える