Django的空格缩进问题

今天一大早继续Django.出现IdentationError,不能进入admin界面。多次查找错误无果,最后沉心一想会不会跟python的缩进有关?在写最初写python的时候没有少受缩进的苦头。最后终于在urls.py中发现了问题,果然是缩进问题,我用vim直接删除了注释符#但是没有将空格删去,导致IdentationError的出现.出错信息和代码如下.

//出错信息
IndentationError at /admin/ unexpected indent (urls.py, line 5) Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Django Version: 1.3 Exception Type: IndentationError Exception Value: unexpected indent (urls.py, line 5) Exception Location: /usr/lib/pymodules/python2.7/django/utils/importlib.py in import_module, line 35 Python Executable: /usr/bin/python Python Version: 2.7.2 Python Path: ['/home/fan/djangoProject/mysite', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '/usr/lib/python2.7/dist-packages/wx-2.6-gtk2-unicode'] Server time: Sun, 8 Apr 2012 19:32:54 -0500

 

1 //urls.py部分代码
2 from django.conf.urls.defaults import patterns, include, url
3 
4 # Uncomment the next two lines to enable the admin:
5 from django.contrib import admin   //这是出问题的地方,这里一定要顶格
6 admin.autodiscover()                   //这里也一样
7  



posted @ 2012-04-09 08:40  木头lbj  阅读(1386)  评论(0编辑  收藏  举报