[Django] #16406: Allow separate access to matches from urlpatterns and extra_context args

41 views
Skip to first unread message

Django

unread,
Jul 4, 2011, 12:51:22 PM7/4/11
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
--------------------------------+------------------------------
Reporter: apollo13 | Owner: nobody
Type: Uncategorized | Status: new
Milestone: | Component: Core (Other)
Version: SVN | Severity: Normal
Keywords: resolvers, reverse | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------+------------------------------
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).

--
Ticket URL: <https://code.djangoproject.com/ticket/16406>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 7, 2011, 4:44:10 PM7/7/11
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: apollo13 | Owner: nobody
Type: | Status: new
Cleanup/optimization | Component: Core (Other)
Milestone: | Severity: Normal
Version: SVN | Keywords: resolvers, reverse
Resolution: | Has patch: 1
Triage Stage: Design | Needs tests: 0
decision needed | Easy pickings: 0
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* has_patch: 0 => 1
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Design decision needed


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:1>

Django

unread,
Sep 20, 2011, 11:02:30 AM9/20/11
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: apollo13 | Owner: nobody
Type: | Status: new
Cleanup/optimization | Component: Core (Other)
Milestone: | Severity: Normal
Version: SVN | Keywords: resolvers, reverse
Resolution: | Has patch: 1
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by jacob):

* stage: Design decision needed => Accepted


Comment:

Good idea!

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:2>

Django

unread,
Feb 20, 2012, 3:48:06 PM2/20/12
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: apollo13 | Owner:
Type: | antoviaque
Cleanup/optimization | Status: new
Component: Core (Other) | Version: SVN
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by antoviaque):

* owner: nobody => antoviaque


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:3>

Django

unread,
Feb 22, 2012, 10:02:04 AM2/22/12
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: apollo13 | Owner:
Type: | antoviaque
Cleanup/optimization | Status: new
Component: Core (Other) | Version: SVN
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by apollo13):

New and cleaner patch, but it does change behavior (see changes of the doc
file)

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:4>

Django

unread,
Feb 24, 2012, 3:02:42 PM2/24/12
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
--------------------------------------+------------------------------------
Reporter: apollo13 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: SVN
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by antoviaque):

* owner: antoviaque => nobody


Comment:

Looks like you beat me to the update apollo : )

I've added a test specific to the behavior change though, you may want to
integrate it in your patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:5>

Django

unread,
Feb 24, 2012, 4:32:21 PM2/24/12
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
--------------------------------------+------------------------------------
Reporter: apollo13 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: SVN
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by anonymous):

If your patch includes my changes that should be fine…

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:6>

Django

unread,
Jun 25, 2014, 7:04:45 AM6/25/14
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
--------------------------------------+------------------------------------
Reporter: apollo13 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:

Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1


Comment:

Patch no longer applies cleanly.

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:8>

Django

unread,
Feb 12, 2021, 12:19:59 PM2/12/21
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
--------------------------------------+------------------------------------
Reporter: Florian Apolloner | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by David Smith):

* easy: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:9>

Django

unread,
Apr 30, 2021, 12:05:19 PM4/30/21
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
--------------------------------------+------------------------------------
Reporter: Florian Apolloner | Owner: ppalex
Type: Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev

Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by ppalex):

* owner: nobody => ppalex
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:10>

Django

unread,
Jun 24, 2021, 3:33:33 PM6/24/21
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alexandre
Type: | Prieto Pantoja

Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Alexandre Prieto Pantoja):

Hello,

I'am trying to figure out the context of this ticket but I am rather stuck
on the resolution until now.

I reproduced the use case with the information in the ticket. My code is
now the is the following:


== views.py file:
{{{
#!python
def homepage(request, *args, **kwargs):l
links = []
langs = settings.LANGUAGES
match = resolve(request.path)

for lang in langs:
with translation.override(lang[0]):
links.append(reverse(match.url_name, args=match.args,
kwargs=match.kwargs))

message = _('Welcome to our site!')

return render(request, 'ticket_16406/homepage.html', {'message':
message, 'links':links})
}}}


== url.py file:

{{{
#!python
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.urls import path, re_path
from django.utils.translation import gettext_lazy as _
from ticket_16406 import views


urlpatterns = [
path(_('admin/'), admin.site.urls),
]
urlpatterns += i18n_patterns(
re_path(_(r'^home/(?P<slug>[\w-]+)/$'), views.homepage, {'extra':
True}, name="homepage"),
)

}}}

== template
{{{

{% for link in links %}
<a href={{link}}>{{link}}</a>
{% endfor %}
}}}

I have access to content in different languages in my template.

I don't find the problem I have to tackle here.

Could you give me  more information/details on  "why the patch no longer
applies cleanly"?

It would be a great help. Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:11>

Django

unread,
Jun 25, 2021, 2:36:26 PM6/25/21
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alexandre
Type: | Prieto Pantoja
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alexandre Prieto Pantoja):

* cc: Alexandre Prieto Pantoja (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:12>

Django

unread,
Oct 16, 2021, 10:01:28 AM10/16/21
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Anvesh
Type: | Mishra

Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anvesh Mishra):

* owner: Alexandre Prieto Pantoja => Anvesh Mishra


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:13>

Django

unread,
Dec 13, 2021, 1:14:36 PM12/13/21
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Pedro Schlickmann Mendes):

Replying to [comment:9 David Smith]:
Can you give us more details on why the patch no longer applies cleanly?

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:14>

Django

unread,
Jan 27, 2022, 7:11:25 AM1/27/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy

Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alokik Roy):

* owner: Anvesh Mishra => Alokik Roy


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:15>

Django

unread,
Feb 6, 2022, 5:44:50 AM2/6/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Alokik Roy):

PR of my work so far:
https://github.com/django/django/pull/15402

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:16>

Django

unread,
Feb 25, 2022, 8:25:28 AM2/25/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alokik Roy):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:17>

Django

unread,
Feb 25, 2022, 9:47:46 AM2/25/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


Comment:

The patch is missing tests (all code changes require tests). "Needs tests"
is checked if there is a patch without tests, not an indication that tests
are required. Also the documentation is incomplete. Please review the
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/submitting-patches/#patch-review-checklist patch review checklist] for
all requirements.

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:18>

Django

unread,
Mar 5, 2022, 6:22:14 AM3/5/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alokik Roy):

* cc: Alokik Roy (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:20>

Django

unread,
Mar 5, 2022, 6:22:15 AM3/5/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alokik Roy):

* needs_better_patch: 1 => 0


Comment:

Added tests and documentation

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:19>

Django

unread,
Mar 7, 2022, 12:57:53 AM3/7/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:21>

Django

unread,
Mar 13, 2022, 8:35:04 AM3/13/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alokik Roy):

* needs_tests: 1 => 0


Comment:

Requested Tests added.

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:22>

Django

unread,
Mar 28, 2022, 3:12:41 AM3/28/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:23>

Django

unread,
Mar 29, 2022, 4:16:52 AM3/29/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: resolvers, reverse | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0


* needs_tests: 1 => 0

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:24>

Django

unread,
Mar 29, 2022, 7:08:16 AM3/29/22
to django-...@googlegroups.com
#16406: Allow separate access to matches from urlpatterns and extra_context args
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Alokik
Type: | Roy
Cleanup/optimization | Status: closed

Component: Core (URLs) | Version: dev
Severity: Normal | Resolution: fixed

Keywords: resolvers, reverse | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"baf9604ed8fed3e6e7ddfaca2d83c377c81399ae" baf9604]:
{{{
#!CommitTicketReference repository=""
revision="baf9604ed8fed3e6e7ddfaca2d83c377c81399ae"
Fixed #16406 -- Added ResolveMatch.captured_kwargs and extra_kwargs.

Thanks Florian Apolloner for the review and implementation idea.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/16406#comment:25>

Reply all
Reply to author
Forward
0 new messages