On Fri, 2009-01-16 at 12:46 +1100, Ian Cullinan wrote:
> Actually, it's not the url() function that makes it work, it's specifying the 
> view function by name.
> 
> urlpatterns = patterns('',
>     (r'^FaceSearch/search/$', 'facesearch.views.start_search'),
> )
> 
> works,
> 
> from facesearch.views import start_search
> urlpatterns = patterns('',
>     (r'^FaceSearch/search/$', start_search),
> )
> 
> doesn't.
> 
> Why doesn't it work when you pass a function reference for the view?
> When you put a string in patterns, reverse() works by sting or
> function reference.
> 
> http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse seems
> to imply that it should work either way. Is this a bug?

It does work either way, although function references are a bit more
fragile, since the "name" of the function reference varies a bit
depending upon how it's imported.

However, the real problem was in your first message. You wrote:

        >>> from django.core.urlresolvers import reverse
        
        >>> from facesearch.views import start_search
        
        >>> reverse(start_search)
        
The reverse() function expects a string as its first argument. You're
passing a function object. That line kind of only worked by accident
(well, it didn't work at all, but it looked like it did). Pass in a
string and things will go much better.

Of course, then you're more likely to hit the problem with trying to
match the function name exactly as imported, so it's better to use the
"name=..." version of URL patterns as it's more robust and tends to lead
to cleaner code.

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 [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to