您当前的位置: 首页 >  分类

Django博客系统(写博客页面展示分类)

IT之一小佬 发布时间:2021-10-02 16:51:41 ,浏览量:3

1. 查询数据并展示

1.查询分类文章数据并通过context传递给HTML

from home.models import ArticleCategory
class WriteBlogView(LoginRequiredMixin,View):

    def get(self,request):
        # 获取博客分类信息
        categories = ArticleCategory.objects.all()

        context = {
            'categories': categories
        }
        return render(request,'write_blog.html',context=context)

2.在write_blog.html文件中使用模板语言展示数据


栏目 {% for category in categories %}
关注
打赏
1688896170
查看更多评论
0.0535s