Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Getting the name of a matched URL pattern
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nick Fishman  
View profile  
 More options Jul 1, 9:56 pm
From: Nick Fishman <bsdlogi...@bsdlogical.com>
Date: Wed, 1 Jul 2009 21:56:59 -0400
Local: Wed, Jul 1 2009 9:56 pm
Subject: Getting the name of a matched URL pattern
Hey everyone,

I'm working with Django's named URL patterns, and was wondering how to
fetch the name of the URL pattern that triggered the view. For
example, with the following urlpatterns

urlpatterns = patterns('',
    url(r'^archive/(\d{4})/$', archive, name="full-archive"),
    url(r'^archive-summary/(\d{4})/$', archive, {'summary': True},
"arch-summary"),
)

is there any way to fetch the name="full-archive" and
name="arch-summary" parameter from inside the view?

I found a thread that talks about this same issue
(http://stackoverflow.com/questions/1042211/get-name-for-matched-url-p...),
but the solution requires duplicating the URL pattern name in a
dictionary.

Thanks,

Nick


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
greatlemer  
View profile  
 More options Jul 2, 2:03 am
From: greatlemer <greatle...@googlemail.com>
Date: Wed, 1 Jul 2009 23:03:32 -0700 (PDT)
Local: Thurs, Jul 2 2009 2:03 am
Subject: Re: Getting the name of a matched URL pattern
On Jul 1, 9:56 pm, Nick Fishman <bsdlogi...@bsdlogical.com> wrote:

Hi,

I came across a similar problem when trying to put together my app for
handling menus (since I wanted to be able to specify menu items by url
names).  Anyway the following was the method I finally came up with
which seems to work just fine for me -
http://code.google.com/p/greatlemers-django-tools/source/browse/trunk...

Hope this helps.

--
G


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shawn Milochik  
View profile  
 More options Jul 2, 12:11 pm
From: Shawn Milochik <shawn.m...@gmail.com>
Date: Thu, 2 Jul 2009 12:11:00 -0400
Subject: Re: Getting the name of a matched URL pattern

On Jul 1, 2009, at 9:56 PM, Nick Fishman wrote:

Can you get what you need within the view by using  
request.build_absolute_uri()?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Fishman  
View profile  
 More options Jul 2, 9:17 pm
From: Nick Fishman <bsdlogi...@bsdlogical.com>
Date: Thu, 2 Jul 2009 21:17:34 -0400
Local: Thurs, Jul 2 2009 9:17 pm
Subject: Re: Getting the name of a matched URL pattern

> Hi,

> I came across a similar problem when trying to put together my app for
> handling menus (since I wanted to be able to specify menu items by url
> names).  Anyway the following was the method I finally came up with
> which seems to work just fine for me -
> http://code.google.com/p/greatlemers-django-tools/source/browse/trunk...

> Hope this helps.

> --
> G

That looks like it does exactly what I'm looking for. I wish there
were a way to find the URL name without having to call the resolver
again, but your method looks pretty fast. Thanks!

Shawn, request.build_absolute_uri() returns a full path like
http://hostname/path/goes/here/, but it doesn't tell me the name of
the URL pattern that caused the request to be resolved to a particular
view.

Nick


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google