django常用函数
2015-12-23 15:09
489 查看
1.from django.shortcuts import get_object_or_404
blog = get_object_or_404(Blog,pk=id)
get_object_or_404对应的是get()函数
如果没有获取到object,就返回404页面
2.from django.shortcuts import render
render(request,template,context)
context ------>dict
3.from django.shortcuts import get_list_or_404
bloglist = get_list_or_404(Blog,name='apress')
get_list_or_404对应的是filter()函数
如果返回的list是空的,就返回404页面
blog = get_object_or_404(Blog,pk=id)
get_object_or_404对应的是get()函数
如果没有获取到object,就返回404页面
2.from django.shortcuts import render
render(request,template,context)
context ------>dict
3.from django.shortcuts import get_list_or_404
bloglist = get_list_or_404(Blog,name='apress')
get_list_or_404对应的是filter()函数
如果返回的list是空的,就返回404页面
相关文章推荐
- Spark on Yarn: Where Have All the Memory Gone?
- 初识GoAhead
- beego 如何自定error
- 例题8-5 UVA 11054 Gergovia的酒交易
- goto语句的替换方法--用while
- Google 推出的 31 套在线课程
- 在安卓上使用Goldendict 查字典
- golang的各种数据格式的互相转换
- golang 的编译安装以及supervisord部署
- Intent中的四个属性 action category data extras
- poj 2007 Scrambled Polygon 【极角排序】
- 如何更改WORDPRESS后台登录页面LOGO
- Google 搜索
- 论文笔记:going deeper with convolutions
- SSHException: Incompatible ssh peer (no acceptable kex algorithm)
- Google Map通过经纬度获取详细地址
- lanczos bidiagonalization(1)
- Good Bye2015,Hello 2016
- 类别(Categories)和扩展/匿名类别(extensions)及其延伸使用
- django中使用日志输出