当我python manage.py runserver
在 PowerShell 上运行时,出现以下错误:
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)),
)