- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 Django 的新手。我正在尝试创建 UserProfile。首先,我在 models.py 中创建了一个模型及其处理程序,如下所示。
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.pyAUTH_PROFILE_MODULE = "lib.UserProfile"
其中 lib 是包含 init.py 、models.py 和所有内容的根文件夹。
然后我删除了集合中的所有当前用户,当我从管理面板重新输入它们时,会自动创建一个新集合 lib_userprofile,其中包含我在模型中提到的字段。现在我创建了一个 View 如下
class CurrentUser(APIView):
authentication_classes = (authentication.TokenAuthentication,)
def get(self,request):
if request.user.is_authenticated():
profile=request.user.get_profile()
return Response(profile)
但是给我以下错误..
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']
任何帮助将不胜感激..我发现了很多关于这个错误的问题,但我无法解决错误..
最佳答案
我已经解决了这个错误。我正在回答我自己的问题,因为它可能会帮助面临同样问题的人。
我在 get_profile 函数中遇到错误,所以我检查了位于 /contrib/auth/models.py
的 models.py 文件的代码,在 get_profile() 函数的第 383 行通过替换 user__id__exact=self.id with user = self.id
并且运行良好。
关于python - Django 错误 : userprofile matching query does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20113779/
我在 SQL 查询中使用了一个简单的 IF NOT EXISTS/WHERE NOT EXISTS 语句(我都尝试过),但我总是收到 mysql 错误,不知道为什么。尝试使用不同的引号,检查我的 My
我有 2 个表:tbl1 和 tbl2。我想从 tbl1 返回一行,其中包含以下列:col1、col2、col3、can_be_deleted 、有重要项目。这个想法是,can_be_deleted
如果您是 "t1".persona_1_id = 2,则预期结果应返回 persona_id = 4。 like --- id persona_1_id persona_2_id liked 1 2
我遇到了这个用于执行幂等插入的 github SQL 代码示例。完全按照我想要的方式工作。我不想使用 EXISTS,因为我觉得它有点困惑。可以使用联接对相同的操作进行编码吗? 下面是我在 github
public bool CheckTblExist(string TblName) { try { string cmTxt = "s
表1 Id Name DemoID 1 a 33 2 b 44 3 c 33 4 d 33 5 e 44 表2 Id DemoID IsT
我对 SQL 非常陌生。我想知道当我使用“IF EXISTS”或“IF NOT EXISTS”时会发生什么。例如:以下两个语句有什么区别: 语句 1:(存在) IF EXISTS( SELECT OR
我正在更新 exist-db 集合中的 XML 文件,我必须检查是否存在 id 以决定是否必须在我的文档中替换或插入某些内容。 我注意到随着文件的增长,查询执行时间显着恶化,我决定为我的文件添加一个索
我有一个正在尝试更新的数据库,但我不明白为什么会收到有关不存在的列的奇怪错误。当我使用“heroku pg:psql”访问数据库时,我完全可以看到该列。我找到了couple其他questions遇到类
我有一个这样的查询 SELECT ... FROM ... WHERE (SELECT EXISTS (SELECT...)) which did not return anything th
我有一个可以对数据库执行插入和更新的程序,我从 API 获取数据。这是我得到的示例数据: $uname = $get['userName']; $oname = $get['offerNa
我的批处理文件中有这个脚本 -- if not exist "%JAVA_HOME%" ( echo JAVA_HOME '%JAVA_HOME%' path doesn't exist) -
有没有办法让 Directory.Exists/File.Existssince 区分大小写 Directory.Exists(folderPath) 和 Directory.Exists(folde
考虑使用这两个表和以下查询: SELECT Product. * FROM Product WHERE EXISTS ( SELECT * FROM Codes
我正在使用 Subclipse 1.6.18 使用 Eclipse 3.72 (Indigo) 来处理 SVN 1.6 存储库。这一切都在 Ubuntu 下运行。 我有一个项目,在我更新我的 Ecli
我正在尝试使用 Terraform 配置 Azure 存储帐户和文件共享: resource "random_pet" "prefix" {} provider "azurerm" { versi
我有兴趣为需要使用 NOT EXISTS 的应用程序编写查询。子句来检查一行是否存在。 我正在使用 Sybase,但我想知道一般 SQL 中是否有一个示例,您可以在其中编写具有 NOT EXISTS
我正在尝试使用 Terraform 配置 Azure 存储帐户和文件共享: resource "random_pet" "prefix" {} provider "azurerm" { versi
下面是代码示例: CREATE TABLE #titles( title_id varchar(20), title varchar(80)
我曾经这样编写 EXISTS 检查: IF EXISTS (SELECT * FROM TABLE WHERE Columns=@Filters) BEGIN UPDATE TABLE SET
我是一名优秀的程序员,十分优秀!