Andrew-liu / my_blog_tutorial

It's the example of the development of blog by Django and Pure.
382 stars 206 forks source link

8.动态url #7

Closed Justin-YGG closed 9 years ago

Justin-YGG commented 9 years ago
#views 里面try是应该有返回的?要返回给post.html?
 def detail(request, id):
      try:
          post = Article.objects.get(id=str(id))
          return render(request,'post.html',{'post': post})#(这样?)
      except Article.DoesNotExist:
            raise Http404
            return render(request,'post.html',{'post':post})
Andrew-liu commented 9 years ago

贴代码最好用markdown形式, 这样没有缩进不太好看

最后一句return很清楚的说了 返回给post.html

下面是这一段的源码

def detail(request, id):
    try:
        post = Article.objects.get(id=str(id))
    except Article.DoesNotExist:
        raise Http404
    return render(request, 'post.html', {'post' : post})
Justin-YGG commented 9 years ago

OK,多谢,刚才理解错了,提问的格式已改。