Django reverse routing - solution to case where reverse routing is less specific than forward routing -
i have route defined follows:
(r'^edit/(\d+)/$', 'app.path.edit')
i want use reverse function follows:
url = reverse('app.path.edit', args=('-id-',))
the generated url gets passed js function, , client side code replace '-id-' correct numeric id. of course won't work, because 'reverse' function won't match route, because url defined containing numeric argument.
i can change route accept type of argument follows, loose specificity:
(r'^edit/(.+)/$', 'app.path.edit'
i create separate url each item being displayed, i'll displaying many items in list, seems waste of bandwidth include full url each item.
is there better strategy accomplish want do?
you can rewrite regexp this:
(r'^edit/(\d+|-id-)/$', 'app.path.edit')
but prefer this:
(r'^edit/([^/]+)/$', 'app.path.edit') # can still differ "edit/11/" , "edit/11/param/"
usually anyway need check entity existent get_object_or_404 shortcut or similar, bad have more accurate incoming data id can contain characters.
Comments
Post a Comment