如何在Django中获取url变量?
我的视图中有类似的内容。py: 和comment.html的一个片段: 我想用那页上的帖子替换XXXXXXXXXXXX。url格式如下所示:如何在Django中获取url变量?,django,url,Django,Url,我的视图中有类似的内容。py: 和comment.html的一个片段: 我想用那页上的帖子替换XXXXXXXXXXXX。url格式如下所示: http://localhost:8000/post/my-post-name/ DetailView将对象存储在self.object中。 在get_context_数据中,您可以在筛选器中使用它: context['comments'] = Comments.objects.filter(post=self.object).order_by('-pu
http://localhost:8000/post/my-post-name/
DetailView将对象存储在self.object中。
在get_context_数据中,您可以在筛选器中使用它:
context['comments'] = Comments.objects.filter(post=self.object).order_by('-pub_date')
您只需执行self.request.post,URL.py中的条目是什么?
url(r'^post/(?P<slug>[\w\-_]+)/$', 'page.views.PostDetail', name='post-detail'),
http://localhost:8000/post/my-post-name/
context['comments'] = Comments.objects.filter(post=self.object).order_by('-pub_date')