X
X
xozzslip2016-05-17 14:17:33
Django
xozzslip, 2016-05-17 14:17:33

How to nest menu items of arbitrary depth?

How to make url pattern for menu of arbitrary view depth:

1) ааа
    1.1) ббб
    1.2) ббб
          1.2.1) ввв
2) ггг
    2.1) ддд

So that if you enter site.ru/1/1.2/1.2.1 into the address bar, then the list [1, 1.2, 1.2.1] is passed to the view.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2016-05-17
@xozzslip

This is a very bad decision, it is better not to try to use variable length arguments in views, but anything is possible.

urlpatterns = [
    url(r'^((\d+(\.\d+)*/)+)$', varargs),
]

def varargs(request, path, *args):
    path_list = [i for i in path.split('/') if i]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question