[Django]-'str' object is not callable,how to deal?

6👍

You need to give the actual view to url():

urlpatterns = patterns('',
    url(r'^time/$', current_time),
    url(r'^what/$', what),
    url(r'^hello/([a-zA-Z0-9]+)', hello),
)

Note that I removed the quotes around what and the other view functions.

You can still use strings in the url() configurations, but then you need to use a <modulename>.<viewname> syntax or name the module in the first argument to patterns() (the string), and then you also don’t need to import the functions:

urlpatterns = patterns('',
    url(r'^time/$', 'hello_django.views.current_time'),
    url(r'^what/$', 'hello_django.views.what'),
    url(r'^hello/([a-zA-Z0-9]+)', 'hello_django.views.hello'),
)

or

urlpatterns = patterns('hello_django.views',
    url(r'^time/$', 'current_time'),
    url(r'^what/$', 'what'),
    url(r'^hello/([a-zA-Z0-9]+)', 'hello'),
)

See the detailed URL dispatcher documentation.

Leave a comment