为何Wagtail关键字会追加到新建应用名称后导致Django报错?
Hey there! Let's sort out this frustrating issue you're facing while setting up your first Wagtail blog app.
问题根源
That error No module named 'blog.apps.BlogConfigwagtail' tells us exactly what's wrong: in your project's settings.py, you accidentally merged your blog app's configuration with a Wagtail-related entry into a single invalid string. Instead of keeping them as separate list items in INSTALLED_APPS, you ended up with something like 'blog.apps.BlogConfigwagtail' — which Django can't recognize because that module doesn't exist.
解决步骤
Follow these simple fixes:
- Open your project's
settings.pyfile (usually in the root project folder, alongsidemanage.py). - Scroll down to the
INSTALLED_APPSlist. - Look for any line that combines your blog app config with "wagtail" — it'll look something like this (wrong):
# ❌ Wrong entry 'blog.apps.BlogConfigwagtail', - Split this into two separate, correct entries. Your blog app config and Wagtail's apps should each be their own item in the list. Here's how it should look:
INSTALLED_APPS = [ # ... keep your existing core Django apps here (like 'django.contrib.admin', etc.) # Your custom blog app 'blog.apps.BlogConfig', # Wagtail's required apps (add these if you haven't already) 'wagtail.contrib.forms', 'wagtail.contrib.redirects', 'wagtail.embeds', 'wagtail.sites', 'wagtail.users', 'wagtail.snippets', 'wagtail.documents', 'wagtail.images', 'wagtail.search', 'wagtail.admin', 'wagtail', # ... other dependencies like 'modelcluster', 'taggit' go here too ] - Save the
settings.pyfile. - Run
python manage.py makemigrationsagain — it should work without that error now!
Quick Explanation
Django checks each entry in INSTALLED_APPS to load the corresponding app module. When you mashed your blog's BlogConfig with "wagtail", it tried to find a non-existent module called BlogConfigwagtail inside blog.apps, which obviously doesn't exist. Splitting them into separate entries lets Django find both your custom blog app and Wagtail's apps correctly.
内容的提问来源于stack exchange,提问作者rahim asgari

