【发布时间】:2013-02-08 19:19:37
【问题描述】:
当我在 PowerShell 上运行 python manage.py runserver 时,出现以下错误:
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line
__import__(name)
IndentationError: unexpected indent
但是,我之前从未接触过该文件,当我在 Notepad++ 中打开该文件时,它显示 这个:
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' 的注释。我取消注释url(r'^admin/', include(admin.site.urls)),
在“urls.py”中启用管理员。这是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)),
)
【问题讨论】:
-
已删除答案 - 我不知道发生了什么。
-
问题不在于 importlib,而在于 importlib 试图导入的任何文件。您提到了对 urls.py 的更改-您可能应该发布它。
-
我为 manage.py、settings.py 和 urls.py 尝试了
python -m tabnanny -v <files>,我得到了Clean bill of health,所以我认为这些文件没问题。
标签: django indentation