python - Advanced URLs in Django -
the task write 2 url patterns.
the first 1 take single argument <path>
, can url random depth:
test/dorogi/
or
test/foo/bar/as/deep/as/you/want
the second 1 same first one, number in end.
test/dorogi/1/
it talkes 2 arguments: <path>
, <pk>
. last 1 number.
i made solution first pattern:
url(r'^(?p<path>.*)/', mptt_urls.view(model='activities.models.category', view='activities.views.category', slug_field='slug'), name='activities'),
but how make second 1 , prevent conflicts beteween them?
it should like:
url(r'^...', views.articledetailview.as_view(), name='article-detail'),
just add second parameter regex first pattern:
r'^(?p<path>.*)/(?p<pk>\d+)/$'
but make sure put before first 1 in list of urls.
(note should terminate pattern $, did above.)
Comments
Post a Comment