def query_article_by_id(article_id=0, use_cache=True):
"""
????ID???????
:param article_id: ??ID
:param use_cache: ??????
"""
key = CACHE_KEY_ID + str(article_id)
if use_cache:
cache_result = cache.get(key)
if cache_result:
return cache_result
try:
article = BlogArticle.objects.get(id=article_id)
article = BlogArticle.format_article(article)
cache.set(key, article, CACHE_TIME)
return article
except BlogArticle.DoesNotExist:
return None
评论列表
文章目录