首页 > django中数据库链接是否是持久的

django中数据库链接是否是持久的

django中数据库的链接的被封装起来的,一般不需要直接操作。

但是我想知道django中数据库的链接是一个请求新开一个链接,

还是说可以保持链接,多次使用。


QuerySets are lazy¶

https://docs.djangoproject.com/en/1.7/topics/db/queries/#querysets-are-lazy

QuerySets are lazy – the act of creating a QuerySet doesn’t involve any database activity. You can stack filters together all day long, and Django won’t actually run the query until the QuerySet is evaluated. Take a look at this example:

q = Entry.objects.filter(headline__startswith="What")
q = q.filter(pub_date__lte=datetime.date.today())
q = q.exclude(body_text__icontains="food")
print(q)


楼上的回答是django queryset是在何时去访问数据库
django 1.6新增了配置项CONN_MAX_AGE,默认值是0,在每次请求完之后都关闭对应的数据库连接。
设置成None则保持长连接。

参考官方文档

【热门文章】
【热门文章】