Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Django中获取url变量?_Django_Url - Fatal编程技术网

如何在Django中获取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

我的视图中有类似的内容。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('-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')