Error encountered in django

已查看 4 次
跳至第一个未读帖子

Adrien

未读,
2006年11月19日 20:28:412006/11/19
收件人 Django users
Hi All!

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

limodou

未读,
2006年11月19日 20:41:522006/11/19
收件人 django...@googlegroups.com
I think this error happended because your urls.py is not correctly or
your url option is not match with your code of view. Maybe you can
post your code of urls.py here.

--
I like python!
UliPad <<The Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

Adrien

未读,
2006年11月19日 20:48:032006/11/19
收件人 Django users

> I think this error happended because your urls.py is not correctly or
> your url option is not match with your code of view. Maybe you can
> post your code of urls.py here.

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)

limodou

未读,
2006年11月19日 20:49:552006/11/19
收件人 django...@googlegroups.com
On 11/20/06, Adrien <adrien...@gmail.com> wrote:
>
>
Maybe you made mistake, your code is not urls but view. Please review
the tutorials or url_dispatch document carefully.

Adrien

未读,
2006年11月19日 20:52:392006/11/19
收件人 Django users

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),
)

limodou

未读,
2006年11月19日 21:21:202006/11/19
收件人 django...@googlegroups.com
On 11/20/06, Adrien <adrien...@gmail.com> wrote:
>
>
> Adrien wrote:
> > > I think this error happended because your urls.py is not correctly or
> > > your url option is not match with your code of view. Maybe you can
> > > post your code of urls.py here.
> >
> > 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),

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.

Adrien

未读,
2006年11月19日 22:39:382006/11/19
收件人 Django users

> 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

Ivan Sagalaev

未读,
2006年11月20日 06:44:432006/11/20
收件人 django...@googlegroups.com
limodou wrote:
> Opps, you cannot set a real function object in urls.py

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.

limodou

未读,
2006年11月20日 06:57:472006/11/20
收件人 django...@googlegroups.com
Oh, I don't know that yet, thank you. I'll look at it.
回复全部
回复作者
转发
0 个新帖子