2013-02-08 77 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的解决了这个问题对我来说。

相关问题