2013-02-08 115 views
0

當我在PowerShell中運行python manage.py runserver,我得到了以下錯誤:IndentationError運行manage.py runserver命令Django的時候

File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 
__import__(name) 
IndentationError: unexpected indent 

但是,我從來沒有觸及該文件之前,當我打開記事本該文件++它顯示 這樣的:

if name.startswith('.'): 
    if not package: 
     raise TypeError("relative imports require the 'package' argument") 
    level = 0 
    for character in name: 
     if character != '.': 
      break 
     level += 1 
    name = _resolve_name(name[level:], package, level) 
    __import__(name) #LINE 35 
return sys.modules[name]` 

出了什麼問題?我正在使用Python 2.7和Django 1.4.2在Windows Vista x32上工作 我感謝您的幫助。

這裏是settings.py下的數據庫信息:

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': 'demo',      # Or path to database file if using sqlite3. 
     'USER': '****',      # Not used with sqlite3. 
     'PASSWORD': '*****',     # Not used with sqlite3. 
     'HOST': '127.0.0.1',      # Set to empty string for localhost. Not used with sqlite3. 
     'PORT': '3306',      # Set to empty string for default. Not used with sqlite3. 
    } 
} 

我也取消註釋'django.contrib.admin'在同一個文件中。我在「urls.py」中取消註釋url(r'^admin/', include(admin.site.urls)), 以啓用管理員。這裏是urls.py,這是我從python manage.py startproject

from django.conf.urls import patterns, include, url 

# Uncomment the next two lines to enable the admin: 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
# Examples: 
# url(r'^$', 'demo.views.home', name='home'), 
# url(r'^demo/', include('demo.foo.urls')), 

# Uncomment the admin/doc line below to enable admin documentation: 
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 

# Uncomment the next line to enable the admin: 
url(r'^admin/', include(admin.site.urls)), 

+0

已刪除答案 - 我不知道發生了什麼事。 – 2013-02-08 20:48:32

+0

問題不在於importlib,它在任何文件importlib試圖導入。你提到urls.py的更改 - 你應該發佈。 – 2013-02-08 21:07:04

+0

我想'蟒蛇-m tabnanny -v '的manage.py,settings.py和urls.py和我'health'的清潔提單,所以我認爲這些文件是好的。 – Dombey 2013-02-09 00:59:22

回答

1

使用了在Django標籤是一種不好的做法。爲了解決你的問題,你只能使用空格,我想4個空格。嘗試退格你的代碼,你會發現它是製表符縮進,只使用空格。

0

今天我遇到了同樣的錯誤。 就像Dombey python -m tabnanny -v *報告了Clean bill of health我的所有文件。

我使用Git,所以我試圖運行主分支(其中用於運行罰款),但我得到了同樣的結果。

我不知道是什麼引起了錯誤,但卸載,重新安裝Django的解決了這個問題對我來說。