Python论坛  - 讨论区

标题:[python-chinese] Django新手求救,按照djangobook的教程,结果出现“AttributeError at /now/“错误~~~

2007年01月19日 星期五 01:26

hlddn hlddn.python在gmail.com
星期五 一月 19 01:26:39 HKT 2007

°´ÕÕchapter3ÖеIJ½Ö裺
views.py£º

from django.http import HttpResponse
import datetime

def current_datetime(request):
    now = datetime.datetime.now()
    html = "It is now %s." % now
    return HttpResponse(html)

urls.py£º

from django.conf.urls.defaults import *

from mysite.views import current_datetime

urlpatterns = patterns('',
    (r'^now/$', current_datetime),
)


Ö´ÐÐÒ³ÃæºóÈ´³öÏÖ£º

AttributeError at /now/ 'function' object has no attribute 'rindex' Request
Method: GET  Request URL: http://192.168.0.220:8000/now/  Exception Type:
AttributeError  Exception Value: 'function' object has no attribute
'rindex'  Exception
Location: /usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/urlresolvers.py
in get_mod_func, line 23


ÎÒµÄdjango°æ±¾£º
>>> import django
>>> django.VERSION
(0, 96, 'pre')

ÕâÊÇΪʲô£¿°æ±¾Ì«µÍ£¿ÎÒ¿´chapter2Öеİ汾ÊÇ£º
>>> import django
>>> django.VERSION
(1, 0, 'official')

ÎÒʹÓõÄÊÇFreeBSD£¬PortsÄܰ²×°µ½µÄ×îоÍÊÇÉÏÃæµÄÄǸö0.96 pre°æÁË
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070119/8cfb3a73/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年01月19日 星期五 07:45

Xupeng Yun recordus在gmail.com
星期五 一月 19 07:45:38 HKT 2007

在07-1-19,hlddn <hlddn.python at gmail.com> 写道:
>
> from django.conf.urls.defaults import *
>
> from mysite.views import current_datetime
>
> urlpatterns = patterns('',
>     (r'^now/$', current_datetime),
>
> )
>
> 我记得除非是开发版本,上边标红色的地方要用字符串的:
(r'^now/$', 'current_datetime'),

-- 
I like Python & Linux.
Blog: http://recordus.cublog.cn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070119/bed2a591/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年01月19日 星期五 08:18

limodou limodou在gmail.com
星期五 一月 19 08:18:48 HKT 2007

On 1/19/07, Xupeng Yun <recordus在gmail.com> wrote:
> 在07-1-19,hlddn <hlddn.python在gmail.com> 写道:
> > from django.conf.urls.defaults import *
> > from mysite.views import current_datetime
> >
> > urlpatterns = patterns('',
> > (r'^now/$', current_datetime),
> >
> >
> > )
> >
> 我记得除非是开发版本,上边标红色的地方要用字符串的:
> (r'^now/$', 'current_datetime'),
>

不错,不能是0.95版本,需要开发版。

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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年01月19日 星期五 10:50

hlddn hlddn.python在gmail.com
星期五 一月 19 10:50:32 HKT 2007

On 1/19/07, Xupeng Yun <recordus在gmail.com> wrote:
>
> ÔÚ07-1-19£¬hlddn <hlddn.python在gmail.com> дµÀ£º
> >
> > from django.conf.urls.defaults import *
> >
> > from mysite.views import current_datetime
> >
> > urlpatterns = patterns('',
> >     (r'^now/$', current_datetime),
> >
> >
> > )
> >
> > ÎҼǵóý·ÇÊÇ¿ª·¢°æ±¾£¬Éϱ߱êºìÉ«µÄµØ·½ÒªÓÃ×Ö·û´®µÄ£º
> (r'^now/$', 'current_datetime'),


 лл¸÷λ£¬Ê¹ÓÃÉÏÃæµÄ·½Ê½Ò²²»ÐУ¬¿ÉÄܾÍÊǰ汾ÎÊÌâ¡£ÄѵÀ´ó¼ÒÓõͼÊÇ¿ª·¢°æ±¾£¿
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070119/edfcd940/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年01月19日 星期五 21:21

hlddn hlddn.python在gmail.com
星期五 一月 19 21:21:31 HKT 2007

On 1/19/07, hlddn <hlddn.python在gmail.com> wrote:
>
> On 1/19/07, Xupeng Yun <recordus在gmail.com> wrote:
> >
> > ÔÚ07-1-19£¬hlddn <hlddn.python在gmail.com> дµÀ£º
> > >
> > > from django.conf.urls.defaults import *
> > >
> > > from mysite.views import current_datetime
> > >
> > > urlpatterns = patterns('',
> > >     (r'^now/$', current_datetime),
> > >
> > >
> > >
> > > )
> > >
> > > ÎҼǵóý·ÇÊÇ¿ª·¢°æ±¾£¬Éϱ߱êºìÉ«µÄµØ·½ÒªÓÃ×Ö·û´®µÄ£º
> > (r'^now/$', 'current_datetime'),
>
>
>  лл¸÷λ£¬Ê¹ÓÃÉÏÃæµÄ·½Ê½Ò²²»ÐУ¬¿ÉÄܾÍÊǰ汾ÎÊÌâ¡£ÄѵÀ´ó¼ÒÓõͼÊÇ¿ª·¢°æ±¾£¿
>

¸Ä³ÉÕâÑù¾Í¿ÉÒÔÁË

from django.conf.urls.defaults import *

# from mysite.views import current_datetime

urlpatterns = patterns('',
    (r'^now/$', 'mysite.views.current_datetime'),
)
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070119/048b954d/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年01月19日 星期五 21:32

limodou limodou在gmail.com
星期五 一月 19 21:32:12 HKT 2007

> 改成这样就可以了
>
>  from django.conf.urls.defaults import *
> # from mysite.views import current_datetime
>
> urlpatterns = patterns('',
>  (r'^now/$',
> 'mysite.views.current_datetime'),
> )
>

这就是老的用法,你看django的文档就是这样举例的。url dispatch的文档。


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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年01月19日 星期五 22:02

hlddn hlddn.python在gmail.com
星期五 一月 19 22:02:57 HKT 2007

ллÁË

On 1/19/07, limodou <limodou在gmail.com> wrote:
>
> > ¸Ä³ÉÕâÑù¾Í¿ÉÒÔÁË
> >
> >  from django.conf.urls.defaults import *
> > # from mysite.views import current_datetime
> >
> > urlpatterns = patterns('',
> >  (r'^now/$',
> > 'mysite.views.current_datetime'),
> > )
> >
>
> Õâ¾ÍÊÇÀϵÄÓ÷¨£¬Äã¿´djangoµÄÎĵµ¾ÍÊÇÕâÑù¾ÙÀýµÄ¡£url dispatchµÄÎĵµ¡£
>
>
> --
> I like python!
> UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
> My Blog: http://www.donews.net/limodou
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070119/13864457/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号