--
Ticket URL: <https://code.djangoproject.com/ticket/16391>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* stage: Unreviewed => Design decision needed
* needs_tests: => 0
* needs_better_patch: => 0
Comment:
I wouldn't dismiss the regex check so quickly. Currently, there's a
guarantee that an URL generated with `reverse` will be resolved correctly.
While I understand your reasons to drop this guarantee, we can't do this
lightly.
Note that if #16362 was committed, it would rely on the regex check after
substituting the values. Those two tickets are incompatible.
You could use a something like `r'/users/(?:<% )(\w+)(?: %>)'` or
`r'/users/(\w+|<% \w+ %>)'` in your URLconf — sure, it's a hack.
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:1>
Comment (by jezdez):
This sounds like a great idea for a 3rd party app, that would provide
helpers for JavaScript development.
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:2>
--
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:3>
Comment (by anonymous):
To follow up on this, would also be useful with URI templates:
http://code.google.com/p/uri-templates/
http://bitworking.org/projects/URI-Templates
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:4>
* stage: Design decision needed => Someday/Maybe
Comment:
I agree with jezdez - this is something that'd be best done in a third-
party app. I'm not going to close this ticket, but I am going to stick it
in "someday/maybe" purgatory. I think it's a good idea, but the way to get
this in Django is to start with a solid third-party implementation and
then push to get that in.
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:5>
* cc: mmitar@… (added)
Comment:
Without the support in `reverse` which would allow caller to skip regex
check (but the default would of course still be to check it) it would be
hard to implement such a tag (which I am also missing) without duplicating
code (and thus breaking the DRY principle).
+1 for at least support for `reverse` to have an argument to skip regex
check. Then tag is simple to implement.
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:6>
Comment (by mitar):
Maybe I am wrong. This simple version works quite nicely:
{{{
@register.simple_tag
def urltemplate(viewname):
urlconf = urlresolvers.get_urlconf()
resolver = urlresolvers.get_resolver(urlconf)
prefix = urlresolvers.get_script_prefix()
possibilities = resolver.reverse_dict.getlist(viewname)
if len(possibilities) != 1:
# TODO: Template tags should not the throwing exceptions (only if
TEMPLATE_DEBUG is true)
raise NotImplementedError
possibility, pattern, defaults = possibilities[0]
if len(possibility) != 1:
# TODO: Template tags should not the throwing exceptions (only if
TEMPLATE_DEBUG is true)
raise NotImplementedError
result, params = possibility[0]
for param in params:
result = result.replace('%%(%s)s' % param, '{%s}' % param)
return prefix + result
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:7>
Comment (by mitar):
I add this code (with some improvements) [http://django-
missing.readthedocs.org/en/latest/templatetags.html#missing.templatetags.url_tags.urltemplate
to my library].
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:8>
* component: Core (Other) => Core (URLs)
Comment:
#2615 was a duplicate.
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:9>
* status: new => closed
* resolution: => wontfix
Comment:
I haven't heard of much demand for this feature, so living as a third-
party library seems okay to me.
--
Ticket URL: <https://code.djangoproject.com/ticket/16391#comment:10>