Найти - Пользователи
Полная версия: url tag: Caught NoReverseMatch while rendering
Начало » Django » url tag: Caught NoReverseMatch while rendering
1
cetver
#urls.py
places_url_regex = ur'''
^places
(
(?:/types/(?P<types>\d+(?:-\d+)*))
|
(?:/cuisines/(?P<cuisines>\d+(?:-\d+)*))
|
(?:/avg-bills/(?P<avg_bills>\d+(?:-\d+)*))
|
(?:/cities/(?P<cities>\d+(?:-\d+)*))
|
(?:/sectors/(?P<sectors>\d+(?:-\d+)*))
|
(?:/streets/(?P<streets>\d+(?:-\d+)*))
|
(?:/special/(?P<special>[cabins|calian|children\-animation|children\-room|parking|summer\-verandah|vip-room|wifi|smokers\-room]+))
|
(?:/with/(?P<w>[discounts]+))
|
(?:/page/(?P<page>\d+))
)*
/$
'''
places_url_regex = re.sub( ur'\s+', '', places_url_regex )
urlpatterns = patterns( '',
url( places_url_regex, 'app.places.views.places', name = 'url_places' ),
)
#views.py
def places(request, page = 1, special = '', types = '', cuisines = '', avg_bills = '', cities = '', sectors = '', streets = '', w = ''):
...
Если я пишу в адрессной строке:
/places/types/10/
или в шаблоне:
{% url url_places %}
- все работает, но если в шаблоне пишу:
{% url url_places types=10 %}
происходит исключение:
Caught NoReverseMatch while rendering: Reverse for ‘url_places’ with arguments ‘()’ and keyword arguments ‘{’types': 10}' not found.
Почему так происходит и как заставить это работать ?
ziro
Есть мнение, что Вы несколько преувеличиваете способности reverse match в джанге. Он хорош только для простых выражений типа r'/types/(\d+)/'. На мой взгляд лучше вьюху разбить на несколько, каждая из которых соответствует своей части приведенного Вами регулярного выражения.
cetver
В моем случае вьюх станет очень много. Хотелось бы найти более элегантное решение.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB