Django嵌套URL传递slugs

时间:2014-03-27 23:48:39

标签: django django-urls

我正在寻求完成一个URL:

/group/<group_name>/discussion/<discussion_name>/

我的实施如下所示

project urls.py

url(r'^group/', include('groups.urls')

group urls.py

url(r'^(?P<gslug>[\w-]+)/discussion/', include('discussions.urls')),

讨论urls.py

url(r'^(?P<slug>[\w-]+)',views.discussion_detail, name='discussion_detail'))

不幸的是,在我的views.discussion_detail中,我无法访问gslug和slug。我哪里出错?

讨论viewss.py

def discussion_detail(request, gslug, slug):
  pass //logic in here

1 个答案:

答案 0 :(得分:1)

确保您使用&#39; url&#39;正确地将变量传递到视图中。像这样的模板标签

{% url 'discussion_detail' group.slug discussion.slug %}

如果有效,请告诉我:))