# views.py from django.shortcuts import render from .models import Post, Category def index(request): # 获取所有文章或根据需求筛选 post_list = Post.objects.all().order_by('-created_time')[:10] # 分类映射信息 category_info = { 'name': '非遗传承', 'label': '', 'desc': '探索南京非物质文化遗产的独特魅力与传承故事' } context = { 'post_list': post_list, 'category_info': category_info, 'current_path': request.path } return render(request, 'blog/index.html', context) def category_view(request, category_id): # 分类映射信息 category_map = { 1: {'name': '传统工艺', 'label': '巧夺天工·工艺', 'desc': '探索南京传统手工艺的精湛技艺与匠心传承'}, 2: {'name': '表演艺术', 'label': '梨园雅韵·表演', 'desc': '感受南京传统表演艺术的独特韵味与舞台魅力'}, 3: {'name': '民俗文化', 'label': '人间烟火·民俗', 'desc': '体验南京丰富多彩的民俗活动与民间传统'}, 4: {'name': '口头文学', 'label': '口传心授·文学', 'desc': '领略南京口传文学的语言艺术与文化内涵'}, 5: {'name': '传承人物', 'label': '匠心传承·人物', 'desc': '认识南京非物质文化遗产的传承人与守护者'}, } category_info = category_map.get(category_id, {'name': '非遗传承', 'label': '', 'desc': '探索南京非物质文化遗产的独特魅力'}) # 根据分类ID获取对应的文章 posts = Post.objects.filter(category_id=category_id).order_by('-created_time') context = { 'post_list': posts, 'category_info': category_info, 'current_path': request.path, 'current_category_id': category_id } return render(request, 'blog/index.html', context)