只有登陆界面时没出现任何问题,弄完注册界面后,就无法启动网页,提示不能含有空字节,在网上搜了一下,没有找到能解决的方法,有无懂的指点一下。
(win11,python3.11.2 django4.0.1.0)
建议使用get
>>> Post.post_object.get(title='快速开发')
Traceback (most recent call last):
File "<console>", line 1 , in <module>
File "/home/python/.virtualenvs/py3/lib/python3.5/site-packages/django/db/models/manager.py",
line 85 , in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/python/.virtualenvs/py3/lib/python3.5/site-packages/django/db/models/query.py",
line 385 , in get
self.model._meta.object_name
personal_blog.models.DoesNotExist: Post matching query does not exist.
>>> Post.post_object.all().count()
3
>>> Post.post_object.all().exists() # 查询结果集有数据,exists返回True
True
>>> Post.post_object.filter(id= 1000 ).exists() # 数据中不存在id为 1000 的数据,查询结果集为空,返回
False
False
exclude()方法:返回满足条件之外的数据,实现不等于效果
year、month、day、week_day、hour、minute、second:对日期时间类型的属性进行运算
F对象 专门取对象中某列值的操作,F() 返回的实例用作查询内部对模型字段的引用。这些引用可以用于查询的
filter 中来比较相同模型实例上不同字段之间值的比较。
Q对象 逻辑运算
注意:在django中查询条件的运算符采用两个下划线连接。 比如:
id大于 1 的数据:
翻译成sql语句为: