django matching query does not exist.
2016-03-19 15:22
585 查看
matching query does not exist.
刚开始的代码是这样的,group表在数据库中是空的
这样执行代码后,一直报错 matching query does not exist. 查了一下官方文档,是使用get函数引起的错误。使用get方法时,当找不到匹配的query时,就会报DoesNotExist exception.代码这样改一下就可以了:
刚开始的代码是这样的,group表在数据库中是空的
<pre name="code" class="python">email = 'example@163.com' name = 'develop' if not Group.objects.get(email=email): group = Group() group.name = name group.email = email group.save()
这样执行代码后,一直报错 matching query does not exist. 查了一下官方文档,是使用get函数引起的错误。使用get方法时,当找不到匹配的query时,就会报DoesNotExist exception.代码这样改一下就可以了:
email = 'example@163.com' name = 'develop' try: Group.objects.get(email=email): except Group.DoesNotExist: group = Group() group.name = name group.email = email group.save()
相关文章推荐
- Arduino Uno 硬件电路
- 用js验证字符串是否匹配guid类型20160319
- LeetCode 303. Range Sum Query - Immutable
- UITabbarController
- 让你明白response.sendRedirect()与request.getRequestDispatcher().forward()区别
- 2016.03.19 UINavigationController类相关
- iOS开发-关于UIResponder
- 关于IList、IQueryable、IEnumerable与Func、Expression的关系2-详解
- 一点一滴分析LinkIt™ Smart 7688 webUI
- hdoj-1005-Number Sequences
- iOS开发- UICollectionView详解+实例
- UESTC 485 Game(康托展开,bfs打表)
- UESTC 485 Game(康托展开,bfs打表)
- Access restriction: The type BASE64Encoder is not accessible due to restrict
- request&response笔记
- ueditor1.4.3如何使用绝对目录保存图片
- 【CROC 2016 — QualificationB】【队列模拟】Processing Queries 按时间顺序处理任务 队列长度不超过siz
- The serializable class MyException does not declare a static final serialVersionUID field of type lo
- 【CROC 2016 - Elimination RoundE】【DP】Intellectual Inquiry 长度为m字符串后添加n位最大本质不同子串个数
- UItableView创建