home / django_tickets / tickets

tickets: 16406

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
16406 2011-07-04 16:51:22 2022-03-01 10:39:12 2022-03-06 04:03:08.571238 Accepted assigned Core (URLs) Cleanup/optimization Normal dev   Allow separate access to matches from urlpatterns and extra_context args Currently Django's ''!ResolverMatch'' (eg the one returned by ''urlresolvers.resolve'') gives access to ''args'' and ''kwargs'' which are ready to be passed to the ''func'' being resolved. This does eliminate the possibility of an interesting use-case: Let's assume I have a page written in english and german. I configured my urls using the new urlpatterns like this: {{{#!python urlpatterns = i18n_patterns('', url(_(r'^about/$'), 'about.view', {'some_extra': 'data'}, name='about'), url(_(r'^news/$'), 'home.view', {'some_extra': 'data'}, name='home'), ) }}} I now would like to give my visitors an easy way to access the content in german. So my ''/about'' should have a link to ''/über''. To do that, one could write a templatetag which does the following: {{{#!python match = urlresolvers.resolve('current-url') links = [] for lang in settings.LANGUAGES: translation.activate(lang): links.append(reverse(match.url_name, args=match.args, kwargs=match.kwargs)) # Further logic to display the links in the template }}} This doesn't work since the ''!ResolverMatch'' combined the ''kwargs'' captured from the url-regex with the dictionary supplied for the extra data. I think it would be a great if the ''!ResolverMatch'' would give access to ''kwargs'' and ''extra_context'' separately. There might be more usecases, but that's the only one I can come up with for now. From a quick view at the code it should be possible to do that backwards-compat (eg ''!ResolverMatch.!__getitem!__'' would still return the current result but internally it would use two dictionaries). Alokik-Roe apollo13 resolvers, reverse 1 1 0 0 0 0
Powered by Datasette · Queries took 1.031ms