I'm looking to accomplish a URL as so:

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

My implementation is shown below

project urls.py

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

group urls.py

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

discussion urls.py

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

Unfortunately in my views.discussion_detail I do not have access to both gslug and slug. Where have I gone wrong?

discussion views.py

def discussion_detail(request, gslug, slug):
  pass //logic in here
有帮助吗?

解决方案

Make sure that you're passing variables into the view properly with the 'url' template tag like so

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

Let me know if that works :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top