Son Tran
Son Tran

Reputation: 1536

'str' object is not callable in Django url pattern

In my urls.py file, I have

urlpatterns = patterns('',
                       (r'^$',home_page),
                       #(r'^'+main_cagetory_url_string+'$','home_page'),
                       (r'^(?:cam_sanh|buoi_da_xanh|cam_da_xanh)$','home_page'),
                       (r'^admin/', include(admin.site.urls)),)

I want to use that pattern to access cam_sanh, buoi_da_xanh, cam_da_xanh page. But I receive error:

'str' object is not callable

How can I fix this bug?

Upvotes: 1

Views: 3040

Answers (2)

Necrolyte2
Necrolyte2

Reputation: 748

Django will attempt to lookup the view using the string you provide, however, you need to specify the full view path, aka, 'my_project.view_name'

Alternatively, you can do as Filip suggested and give it the view name as the callback but then you need to import the view into your urls.py file.

Upvotes: 4

Filip Dupanović
Filip Dupanović

Reputation: 33660

For this line specifically, (r'^(?:cam_sanh|buoi_da_xanh|cam_da_xanh)$','home_page'),, the second tuple element should be a callback function, not a string.

This should fix it:

urlpatterns = patterns('',
    (r'^$',home_page),
    (r'^(?:cam_sanh|buoi_da_xanh|cam_da_xanh)$',home_page),
    (r'^admin/', include(admin.site.urls)),
)

Upvotes: 2

Related Questions