0

我正在运行 Mac OS X 10.7,并使用 django-admin.py startproject MyBlog 在 django 中成功创建了一个项目。在这个文件夹中,我有 manage.py、另一个名为 MyBlog 的文件夹和一个我创建的名为 MainBlog 的应用程序文件夹。

我需要将此模块和一个 taggit 模块添加到我的 settings.py 文件夹中,所以我这样做了(可能不正确)。

这里是..

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'MainBlog.taggit',
'MainBlog',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

我也试过

'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'MainBlog.taggit',
'MyBlog.MainBlog',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

这些都不起作用。他们都返回这个错误......

Error: No module named MainBlog

任何帮助将不胜感激。我已经为此苦苦挣扎了好几个小时!

4

1 回答 1

2

The error you are receiving is because django doesn't recognize your app, MainBlog, as a python package.

Django modules are simply Python packages. You need an __init__.py file inside your app directory (MainBlog) to get django to recognize it. See What is __init__.py for?

There are two ways to fix this.

1) Initialize your app with the django script (recommended)

python manage.py startapp MainBlog MainBlog

The startapp command is documented on the django website. This creates a few files in your MainBlog folder to start you out:

MainBlog/
    __init__.py
    models.py
    tests.py
    views.py

2) Manually add an __init__.py file to your MainBlog directory

touch MainBlog/__init__.py
于 2012-08-02T20:37:41.777 回答