Python论坛  - 讨论区

标题:[python-chinese] django book 被datetime例子搞晕了

2008年01月16日 星期三 08:41

cougar2008 cougar2008在gmail.com
星期三 一月 16 08:41:23 HKT 2008

from django.http import HttpResponse
import datetime

def index(request):
    now = datetime.datetime.now()
    html = "It is now %s." % now
    #html = "hi all "
    return HttpResponse(html)

×ÜÊDZ¨´í£º
Request Method:GET
Request URL:http://localhost:8000/datetime/
Exception Type:AttributeError
Exception Value:'module' object has no attribute 'now'
Exception Location:C:\Python25\Lib\site-packages\django\core\handlers\base.py in get_response, line 77





cougar2008
2008-01-16
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080116/d0d8894c/attachment.html 

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

2008年01月16日 星期三 08:53

1234 mydjango在gmail.com
星期三 一月 16 08:53:42 HKT 2008

Õâ¶Î´úÂëÎÒÕâÀïÔËÐÐ ÕýÈ·¡£¡£

2008/1/16, cougar2008 <cougar2008在gmail.com>:
>
>  from django.http import HttpResponse
> import datetime
>
> def index(request):
>     now = datetime.datetime.now()
>     html = "It is now %s." % now
>     #html = "hi all "
>     return HttpResponse(html)
>
> ×ÜÊDZ¨´í£º
>   Request Method: GET Request URL: http://localhost:8000/datetime/ Exception
> Type: AttributeError Exception Value: 'module' object has no attribute
> 'now' Exception Location: C:\Python25\Lib\site-packages\django\core\handlers\base.py
> in get_response, line 77
>
>  ------------------------------
>  cougar2008
> 2008-01-16
>
> _______________________________________________
> 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/20080116/8d974314/attachment.html 

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

2008年01月16日 星期三 08:54

limodou limodou在gmail.com
星期三 一月 16 08:54:14 HKT 2008

2008/1/16 cougar2008 <cougar2008在gmail.com>:

>  from django.http import HttpResponse
> import datetime
>
> def index(request):
>     now = datetime.datetime.now()
>     html = "It is now %s." % now
>     #html = "hi all "
>     return HttpResponse(html)
>
> ×ÜÊDZ¨´í£º
>   Request Method: GET Request URL: http://localhost:8000/datetime/ Exception
> Type: AttributeError Exception Value: 'module' object has no attribute
> 'now' Exception Location: C:\Python25\Lib\site-packages\django\core\handlers\base.py
> in get_response, line 77
>
>  ------------------------------
>  cougar2008
> 2008-01-16
>

See if there is a datetime.py file existed in your  project path. And you
can try to change the code to:

def index(request):
    print datetime.__file__

And see the output in the console, if the module file is what you expected.

-- 
I like python!
UliPad <>: http://code.google.com/p/ulipad/
meide <>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080116/1fd33781/attachment.htm 

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

2008年01月16日 星期三 09:25

cougar2008 cougar2008在gmail.com
星期三 一月 16 09:25:42 HKT 2008

ÔÚshellÖпÉÒÔÔËÐÐ
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> now = datetime.datetime.now()
>>> print now
2008-01-16 09:18:18.111000
>>> print datetime.__file__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute '__file__'

¸Õ²ÅÄã˵Õâ¸öÎÒͻȻÏëµ½£¬djangoÖÐÕâ¸öviewsÎÒÆðµÄÃû×ÖÊÇdatetime.py   µ«ÊÇÏÖÔڸijÉmydatetime.py»¹ÊDz»ÐÐ




cougar2008
2008-01-16



·¢¼þÈË£º limodou
·¢ËÍʱ¼ä£º 2008-01-16 08:56:27
ÊÕ¼þÈË£º python-chinese在lists.python.cn
³­ËÍ£º 
Ö÷Ì⣺ Re: [python-chinese]django book ±»datetimeÀý×Ó¸ãÔÎÁË




2008/1/16 cougar2008 <cougar2008在gmail.com>:

from django.http import HttpResponse
import datetime

def index(request):
    now = datetime.datetime.now()
    html = "It is now %s." % now
    #html = "hi all "
    return HttpResponse(html)

×ÜÊDZ¨´í£º
Request Method:GET
Request URL:http://localhost:8000/datetime/
Exception Type:AttributeError
Exception Value:'module' object has no attribute 'now'
Exception Location:C:\Python25\Lib\site-packages\django\core\handlers\base.py in get_response, line 77





cougar2008
2008-01-16

See if there is a datetime.py file existed in your  project path. And you can try to change the code to:

def index(request):
    print datetime.__file__

And see the output in the console, if the module file is what you expected. 


-- 
I like python! 
UliPad <>: http://code.google.com/p/ulipad/
meide <>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou 
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080116/32da62f3/attachment.htm 

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

2008年01月16日 星期三 10:29

cougar2008 cougar2008在gmail.com
星期三 一月 16 10:29:44 HKT 2008

¿ÉÒÔÁË£¬¹ûÈ»ÊÇÕâ¸öviewsµÄÃû×Ö¸údatetimeµÄÃû×Ö³åÍ»ÁË£¬£º£©²»¹ýÖ»¸ÄÕâ¸öÃû×Ö»¹²»¹»£¬»¹Òª°ÑÒÔÇ°µÄdatetime.pyŪ³öÀ´µÄdatetime.pycɾ³ý²Å¿ÉÒÔ²»³åÍ»

лл£º£©




cougar2008
2008-01-16



·¢¼þÈË£º limodou
·¢ËÍʱ¼ä£º 2008-01-16 08:56:27
ÊÕ¼þÈË£º python-chinese在lists.python.cn
³­ËÍ£º 
Ö÷Ì⣺ Re: [python-chinese]django book ±»datetimeÀý×Ó¸ãÔÎÁË




2008/1/16 cougar2008 <cougar2008在gmail.com>:

from django.http import HttpResponse
import datetime

def index(request):
    now = datetime.datetime.now()
    html = "It is now %s." % now
    #html = "hi all "
    return HttpResponse(html)

×ÜÊDZ¨´í£º
Request Method:GET
Request URL:http://localhost:8000/datetime/
Exception Type:AttributeError
Exception Value:'module' object has no attribute 'now'
Exception Location:C:\Python25\Lib\site-packages\django\core\handlers\base.py in get_response, line 77





cougar2008
2008-01-16

See if there is a datetime.py file existed in your  project path. And you can try to change the code to:

def index(request):
    print datetime.__file__

And see the output in the console, if the module file is what you expected. 


-- 
I like python! 
UliPad <>: http://code.google.com/p/ulipad/
meide <>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou 
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080116/8e3991db/attachment-0001.htm 

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

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

    你的回复:

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

    Zeuux © 2024

    京ICP备05028076号