django book 被datetime例子搞晕了

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

django book 被datetime例子搞晕了

cougar cougar
from django.http import HttpResponse
import datetime
 
def index(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    #html = "hi all "
    return HttpResponse(html)
 
总是报错:
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 [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: django book 被datetime例子搞晕了

1234-2
这段代码我这里运行 正确。。

2008/1/16, cougar2008 <[hidden email]>:
from django.http import HttpResponse
import datetime
 
def index(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    #html = "hi all "
    return HttpResponse(html)
 
总是报错:
Request Method: GET
Request URL: <a href="http://localhost:8000/datetime/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">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 [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: django book 被datetime例子搞晕了

limodou
In reply to this post by cougar cougar


2008/1/16 cougar2008 <[hidden email]>:
from django.http import HttpResponse
import datetime
 
def index(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    #html = "hi all "
    return HttpResponse(html)
 
总是报错:
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 <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: django book 被datetime例子搞晕了

cougar cougar
在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 "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
 
刚才你说这个我突然想到,django中这个views我起的名字是datetime.py   但是现在改成mydatetime.py还是不行
 

cougar2008
2008-01-16

发件人: limodou
发送时间: 2008-01-16 08:56:27
收件人: [hidden email]
抄送:
主题: Re: [python-chinese]django book 被datetime例子搞晕了
 


2008/1/16 cougar2008 <[hidden email]>:
from django.http import HttpResponse
import datetime
 
def index(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    #html = "hi all "
    return HttpResponse(html)
 
总是报错:
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 <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: django book 被datetime例子搞晕了

cougar cougar
In reply to this post by limodou
可以了,果然是这个views的名字跟datetime的名字冲突了,:)不过只改这个名字还不够,还要把以前的datetime.py弄出来的datetime.pyc删除才可以不冲突
 
谢谢:)
 

cougar2008
2008-01-16

发件人: limodou
发送时间: 2008-01-16 08:56:27
收件人: [hidden email]
抄送:
主题: Re: [python-chinese]django book 被datetime例子搞晕了
 


2008/1/16 cougar2008 <[hidden email]>:
from django.http import HttpResponse
import datetime
 
def index(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    #html = "hi all "
    return HttpResponse(html)
 
总是报错:
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 <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese