没有名为blog的模块

-4 投票
1 回答
1330 浏览
提问于 2025-04-17 18:34

我刚开始学习Django,现在正在看一本叫做《使用Django进行Python网页开发》的书,想要创建一个简单的博客。我选择了一个叫blog的应用,并使用sqlite3来测试,但在运行命令./manage.py syncdb时出现了错误。

错误信息是:

Error: No module named blog

这是我settings.py文件的一部分:

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

)

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

以下是博客应用中的model.py的全部内容:

from django.db import models

class BlogPost(models.Model):
    title = models.CharField(max_length = 150)
    body = models.TextField()
    timestamp = models.DataTimeField()

我在StackOverflow上搜索了类似的问题,但那些解决方案对我没有用。

1 个回答

1

试试只用博客:

INSTALLED_APPS = (
    .......
    'blog',
    ......
)

撰写回答