私はDjangoの初心者です。私はUserProfileを作成しようとしています。まず、私はlibにはのinitの.pyが含まれているルートフォルダ、モデルで一つのモデルとmodels.pyでそのハンドラは次のよう..Djangoエラー:ユーザープロファイル一致クエリが存在しません
AUTH_PROFILE_MODULE = "lib.UserProfile"
と
class UserProfile(models.Model):
user = models.ForeignKey(User,null=False)
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
その後、編集したsettings.pyを作成しました.pyとすべて。
次に、コレクションの現在のユーザーをすべて削除しました。管理パネルから再入力したときに、新しいコレクションlib_userprofileが自動的に作成されました。今、私は
class CurrentUser(APIView):
authentication_classes = (authentication.TokenAuthentication,)
def get(self,request):
if request.user.is_authenticated():
profile=request.user.get_profile()
return Response(profile)
を次のようにビューをcreartedしかし
UserProfile matching query does not exist.
Request Method: GET
Request URL: http://pawan.demoilab.pune/api/currentuser
Django Version: 1.3.7
Exception Type: DoesNotExist
Exception Value:
UserProfile matching query does not exist.
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/models/query.py in get, line 351
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/var/www/pawan.demoilab.pune/web/api',
'/usr/local/lib/python2.7/dist-packages/Fabric-1.8.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/paramiko-1.12.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/ecdsa-0.10-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/pymongo-2.6.3-py2.7-linux-i686.egg',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/pymodules/python2.7']
任意の助けをしてくださいいただければ幸いです。..エラー、次の私を与えている..私はこのエラーの多くの質問を見つけたが、私はありませんでしたエラーを解決することができます。
助けてください.... – Pawan
'UserProfile'は' User'と 'OneToOne'リレーションを持つ必要があります。また、実際にプロファイルが作成されていますか?名前が与えられていないので、シグナルハンドラの作成は失敗します。実際のコードを表示していない可能性があります。 – Rohan
これをOneToOneFieldに変更しました。管理パネルから新しいユーザーを追加すると、Useprofileは自動的に "_id"というフィールドで作成されます:ObjectId( "528da840ee4340252254e34b")、 "name": ""、 " " user_id ":" 528da840ee4340252254e34a "そして私は正確なコードを表示しています。あなたが実際のものを見つけられないコード。 – Pawan