On Sun, 2008-10-05 at 16:03 -0700, Alexis Bellido wrote:
> After some more reading and testing I'll try to answer myself, if any
> of you could confirm if I'm on the right track please let me know and
> please correct me if I'm not using the right terminology as well:
> 
> First, in my URLConf I have a url pattern like:
> 
> (r'^search/$', 'books.views.search', {}, 'search_page'),
> 
> I'm using a name url pattern here: 'search_page', that's the fourth
> parameter and I've included an empty dictionary as third parameter,
> can I just omit it?

If you just omit it, the fourth parameter will then become the third
parameter and there will be no fourth parameter. That isn't what you
want. The best way to do this in "short form" is to use the url(...)
style of url patterns. To wit:

        url(r'^search/$', 'books.views.search', name='search_page'),
        
There's no real difference between this and the tuple form (internally,
Django converts the tuple form into a url(...) form), but the above
version is a proper Python function call, so you can use keyword
arguments. The fourth argument is called "name", so you can specify it
without needing to give the third argument.

> 
> Then at the revelant place in my view function I have:
> 
> return HttpResponseRedirect(reverse('search_page'))
> 
> It works for me, am I doing it correctly?

That is indeed correct. If you had any arguments in the search pattern,
say,

        url(r'^search2/(\d+)/$', 'books.view.search',
        name='search_page2'),
        
you could write

        reverse('search_page2', args=[42])
        
to reverse that call. The reverse() call takes "args" and "kwargs"
parameters and the former should be a list or a tuple (the kwargs
parameters would be a dictionary). You must call them "args" and
"kwargs" and not use positional parameters, since, for historical
reasons, the second argument of reverse() is something else that you
don't use here.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to