您的位置:首页 > 编程语言 > Go语言

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页面
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: