xinhua_base
This commit is contained in:
28
core/views.py
Normal file
28
core/views.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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, 10) # 每页显示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
|
||||
})
|
||||
|
||||
# Create your views here.
|
||||
Reference in New Issue
Block a user