29 lines
764 B
Python
29 lines
764 B
Python
from django.shortcuts import render, get_object_or_404
|
|
from django.core.paginator import Paginator
|
|
from .models import Article
|
|
|
|
|
|
def article_list(request):
|
|
"""
|
|
显示文章列表的视图函数
|
|
"""
|
|
articles = Article.objects.all().order_by('-created_at')
|
|
paginator = Paginator(articles, 20) # 每页显示10篇文章
|
|
|
|
page_number = request.GET.get('page')
|
|
page_obj = paginator.get_page(page_number)
|
|
|
|
return render(request, 'core/article_list.html', {
|
|
'page_obj': page_obj
|
|
})
|
|
|
|
|
|
def article_detail(request, article_id):
|
|
"""
|
|
显示文章详情的视图函数
|
|
"""
|
|
article = get_object_or_404(Article, id=article_id)
|
|
return render(request, 'core/article_detail.html', {
|
|
'article': article
|
|
})
|