[Fixed]-Django attribute error. 'module' object has no attribute 'rindex'


You probably need to change

from mysite import hello

to something like

from mysite.hello_file import hello_view

And then use:


Because you need to pass a (view) function, not a file or module. As I think mgalgs was trying to explain, but I think a bit unclear for beginners.



I got this error when adding a Class Based View the following way:

url(r'^tv/$', views.MyTemplateView(), name='my_tv'),

of course .as_view() should be added to fix error object has no attribute 'rindex':

url(r'^tv/$', views.MyTemplateView.as_view(), name='my_tv'),


The url pattern should be tuples of strings, not a module. Something like:

urlpatterns = patterns('',

EDIT: You can also pass a callable to patterns. I simply had never seen it done that way before (the docs always pass a string). However, you’re actually passing a module, not a string or a callable (so django gets confused and first treats it like it must be a callable since it’s not a string but then goes back to trying to treat it like a string, hence the call to rindex). Maybe you meant to pass hello.views.hello like so:

urlpatterns = patterns('',

Alternatively, you could change your import line to from mysite.hello.views import hello, or just use the string syntax (I believe 'hello.views.hello' would do it as initially suggested).



Try this

urlpatterns = patterns('',      
    ('r^test/$','hello.views.hello'),  ) 

Leave a comment