You raise a good point about sub menus.
Possibly something like this:
def resolve_urlname(request):
"""Allows us to see what the matched urlname for this
request is within the template"""
from django.core.urlresolvers import resolve
try:
res = resolve(request.path)
if res:
return {
'urlname' : res.url_name,
'urlparts' : res.url_name.split("__")
}
except:
return {}
But then that forces a naming convention which might not be desired.
The other option is to see if the core devs would accept a patch which
allows you to specify a 'urlname group' on the url() method in urls.py..
Cal
On Fri, Jul 6, 2012 at 3:20 PM, Melvyn Sopacua <[email protected]>wrote:
> On 6-7-2012 16:01, Cal Leeming [Simplicity Media Ltd] wrote:
> > I've actually just done a ticket about this..
> >
> > https://code.djangoproject.com/ticket/18584
> >
> > Personally, I think the approach mentioned in the ticket is a far saner
> way
> > of doing things.
>
> Just wondering about this:
> if res:
> return {'urlname' : res.url_name}
>
> a) no else clause, so there's a codepath where no dict is returned
> b) if that can't be reached, then why the if statement.
>
> Other that that, it probably needs a bit of refinement if you're going
> to force a naming convention, then force the convention on how to deal
> with sub menus, so that we can generate stuff like:
> News
> | world
> >> local
> | business
> Polls
> | current
> | recent
> etc and have both "news" and "local" highlighted. For example it makes
> sense for urlnames like this to have a double underscore separator, so
> the urlname for news/local would be news__local.
> Then again, it might be overkill.
> --
> Melvyn Sopacua
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.