Im starting my way to the django arena but this error stopped me from
continuing. I'm a newbie in python and thought that through hands on
experience, I will be able to learn this language especially for the
web.
Here goes the error:
Traceback (most recent call last):
File "c:\django_src\django\core\handlers\base.py" in get_response
65. callback, callback_args, callback_kwargs = resolver.resolve(path)
File "c:\django_src\django\core\urlresolvers.py" in resolve
148. sub_match = pattern.resolve(new_path)
File "c:\django_src\django\core\urlresolvers.py" in resolve
112. self.func = self.get_callback()
File "c:\django_src\django\core\urlresolvers.py" in get_callback
116. mod_name, func_name = get_mod_func(self.callback)
File "c:\django_src\django\core\urlresolvers.py" in get_mod_func
23. dot = callback.rindex('.')
AttributeError at /now/ 'function' object has no attribute 'rindex'
Note: I have encountere this error while trying to copy the code in the
tutorial of "current_datetime"
Thanks in advance
--
I like python!
UliPad <<The Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou
here is my urls.py code
from django.http import HttpResponse
import datetime
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
Oooopssss...
that is my views.py here is my url.py
from django.conf.urls.defaults import *
from web101.views import current_datetime
urlpatterns = patterns('',
(r'^now/$', current_datetime),
)
i have also tried chaing that to
urlpatterns = patterns('',
(r'^web101/now/$', current_datetime),
)
Opps, you cannot set a real function object in urls.py, urls.py need
only string format of a view function, just like:
'apps.views.functionname'
You can see more details in url_dispatch document.
You're the man!!! thanks
In fact the latest Django can use a real function object (which is BTW
very convenient). This was not in 0.95 but given that the book is for
upcoming 1.0 it's OK.