django pk和id

django在同步models时候会自动为每个表创建1个id字段==pk字段。

如下:Question表中只有一条数据。

从表中取数据,如果有则取出;无则激起django自带404.如下:

from polls.models import Question
from django.shortcuts import render,get_object_or_404

技术分享

本文出自 “LannyMa” 博客,请务必保留此出处http://lannyma.blog.51cto.com/4544390/1738793

文章来自:http://lannyma.blog.51cto.com/4544390/1738793
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3