[Bug 409678] Re: We need an equivalent of django's {% url name arguments %} shortcut to named URLs that works on Jinja templates

10 views
Skip to first unread message

Fabricio Campos Zuardi

unread,
Aug 6, 2009, 12:58:21 AM8/6/09
to public...@googlegroups.com
Looking at Django's source, it looks like the URL tag is implemented
using django.core.urlresolvers reverse under the hoods.

The simple fix would be to tweak our current jinjasupport module to add
this reverse function on the environment globals, however I still need
to test if the arguments passing will work or not…

--
We need an equivalent of django's {% url name arguments %} shortcut to named URLs that works on Jinja templates
https://bugs.launchpad.net/bugs/409678
You received this bug notification because you are a member of
Publicvideos Dev Team, which is the registrant for Public Videos.

Status in Public Videos: New

Bug description:
Django has this nice feature of naming url patterns: http://docs.djangoproject.com/en/dev/topics/http/urls/#id2 that is great in order to avoid hardcoding URLs in the models or in the templates.

However, sice we have chosen to replace the default template engine with Jinja2, we miss the nice {% url %} tag too :(

So, this bug is for implementing a global Jinja function we can call that works simillarly, wich means: given an url name and some arguments, it must print the related relative url based on the configured urlpatterns.

Fabricio Campos Zuardi

unread,
Aug 6, 2009, 12:55:17 AM8/6/09
to public...@googlegroups.com
Public bug reported:

Django has this nice feature of naming url patterns:
http://docs.djangoproject.com/en/dev/topics/http/urls/#id2 that is great
in order to avoid hardcoding URLs in the models or in the templates.

However, sice we have chosen to replace the default template engine with
Jinja2, we miss the nice {% url %} tag too :(

So, this bug is for implementing a global Jinja function we can call
that works simillarly, wich means: given an url name and some arguments,
it must print the related relative url based on the configured
urlpatterns.

** Affects: publicvideos
Importance: Undecided
Status: New


** Tags: django+jinja jinja jinja2 templates urlpattern

Fabricio Campos Zuardi

unread,
Aug 6, 2009, 1:07:12 AM8/6/09
to public...@googlegroups.com
it kinda works, although you have to use something like this to pass
arguments:

{{ reverse('test_url', args=['1234']) }}

I will commit the fix that implements this, but we may reopen and
revisit this bug with a better solution in the future

--
We need an equivalent of django's {% url name arguments %} shortcut to named URLs that works on Jinja templates
https://bugs.launchpad.net/bugs/409678
You received this bug notification because you are a member of
Publicvideos Dev Team, which is the registrant for Public Videos.

Status in Public Videos: In Progress

Fabricio Campos Zuardi

unread,
Aug 6, 2009, 1:13:02 AM8/6/09
to public...@googlegroups.com
** Changed in: publicvideos
Status: New => In Progress

** Changed in: publicvideos
Milestone: None => alpha-launch

--
We need an equivalent of django's {% url name arguments %} shortcut to named URLs that works on Jinja templates
https://bugs.launchpad.net/bugs/409678
You received this bug notification because you are a member of
Publicvideos Dev Team, which is the registrant for Public Videos.

Status in Public Videos: In Progress

Fabricio Campos Zuardi

unread,
Aug 6, 2009, 1:50:30 AM8/6/09
to public...@googlegroups.com
fixed on
http://github.com/fczuardi/publicvideos/commit/bfbb0c70fd599dd2d87433faa8d4d92d219b409e

** Changed in: publicvideos
Status: In Progress => Fix Committed

** Changed in: publicvideos
Assignee: (unassigned) => Fabricio Campos Zuardi (fabricio)

--
We need an equivalent of django's {% url name arguments %} shortcut to named URLs that works on Jinja templates
https://bugs.launchpad.net/bugs/409678
You received this bug notification because you are a member of
Publicvideos Dev Team, which is the registrant for Public Videos.

Status in Public Videos: Fix Committed

Fabricio Campos Zuardi

unread,
Jan 4, 2010, 6:54:54 PM1/4/10
to public...@googlegroups.com
note that this will only work if you call render_to_response with the
variables in an object like {'something':foo} instead of locals()

example (urls):
urlpatterns = patterns('',
url(r'^$', 'videos.views.index', name="site_index_url"),

example (views):

return render_to_response("videos/index.html", {'query_text':query_text,'thumbs':thumbs})

example (template):

{{ url('site_index_url') }}

--
We need an equivalent of django's {% url name arguments %} shortcut to named URLs that works on Jinja templates
https://bugs.launchpad.net/bugs/409678
You received this bug notification because you are a member of
Publicvideos Dev Team, which is the registrant for Public Videos.

Status in Public Videos: Fix Committed

Fabricio Campos Zuardi

unread,
Jan 4, 2010, 7:10:16 PM1/4/10
to public...@googlegroups.com
another easy solution is to use dict(locals()) if you want to pass the
locals

--
We need an equivalent of django's {% url name arguments %} shortcut to named URLs that works on Jinja templates
https://bugs.launchpad.net/bugs/409678
You received this bug notification because you are a member of
Publicvideos Dev Team, which is the registrant for Public Videos.

Status in Public Videos: Fix Committed

Reply all
Reply to author
Forward
0 new messages