Задать вопрос

Тел: +7 965 3737 888

466

Просмотров

3

Ответов

Replacing pattern groups by values

This function takes a pattern with groups and replaces them with the given args and/or kwargs. Example:

IMPORTANT: this code is NOT to use replacing Django's reverse function. The example below is just to illustrate how it works.

For a given pattern '/docs/(d+)/rev/(w+)/', args=(123,'abc') and kwargs={}, returns '/docs/123/rev/abc/'.

For '/docs/(?P<id>d+)/rev/(?P<rev>w+)/', args=() and kwargs={'rev':'abc', 'id':123}, returns '/docs/123/rev/abc/' as well.

When both args and kwargs are given, raises a ValueError.

Вопрос полезен? Да0/Нет0
file_3115.py(1.6Кб)
None

Ответы (3):

Ответmarinho:22.08.2011
Ответ полезен? Да0/Нет0

But, BTW, this is not being used as a replacement for reverse. I used the URL example just to make it easier to understand for who is reading :)

Ответmarinho:22.08.2011
Ответ полезен? Да0/Нет0

Adam, yes, I know it, but it's totally another approach for this, and actually, I disagree the way it does and I see it as a really ugly code (one of the ugliest in Django code).

Ответadamlofts:17.08.2011
Ответ полезен? Да0/Нет0

I guess you've looked at django.core.urlresolvers.reverse?