On Wed, May 21, 2014 at 3:40 AM, Jun Tanaka <tna...@gmail.com> wrote:
> Hi there.
>
>
> I hope to know the solution for the following:
> say, there are several links to one function but I would like to identify
> which link that come from.
>
> url.py looks
>
>     (r'^link1/$', 'project.apps.main.get'),
>     (r'^link2/$', 'project.apps.main.get'),
>     (r'^link3/$', 'project.apps.main.get'),
>     (r'^link4/$', 'project.apps.main.get'),
>
> In 'get' function, how can I know which link does that come from? Later, I
> want to get a parameter , 1, 2, 3, 4 in that function.
>
> If anyone have a good idea? please teach me.

You can add arguments to send to the view in the url:

https://docs.djangoproject.com/en/1.6/topics/http/urls/#passing-extra-options-to-view-functions

Eg:

urlpatterns = patterns('',
    url(r'^link1/$', 'project.apps.main.get', { 'type': 'link1' }),
    url(r'^link2/$', 'project.apps.main.get', { 'type': 'link2' }),
    url(r'^link3/$', 'project.apps.main.get', { 'type': 'link3' }),
    url(r'^link4/$', 'project.apps.main.get', { 'type': 'link4' }),
)

Make sure that you use the url() function rather than a raw tuple.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1Kjey_jLvi-GsNq0kOFU2PzsXVTx231nrOxrVBHkHsx%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to