baker95935

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

思路整理

1 先在urls.py中,定义路由获取的格式

  url(r'^detail/(\d+)/$', views.blog_detail),

2 然后在views.py,定义数据获取的方法

def blog_detail(request,id):
    blog_detail=BlogsPost.objects.get(id=id)
    return render(request,'detail.html', {'blog_detail':blog_detail})

3 然后在detail.html的模板页中,对数据进行展示

       <h2>{{ blog_detail.title }}</h2>
        <p>{{ blog_detail.timestamp }}</p>
        <p>{{ blog_detail.body }}</p>

that's all! enjoy it!

posted on 2018-06-12 16:22  baker95935  阅读(293)  评论(0编辑  收藏  举报