You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django项目重命名app为article后遇ModuleNotFoundError求简易方案

Fixing "ModuleNotFoundError: No module named 'article'" After Renaming Django App

Hey there, let's get this sorted out quickly—no need to rebuild the whole project! You've already done the core steps, but there are a few small, easy-to-miss things that might be causing this error. Here's a straightforward checklist to fix it:

1. Double-Check Your apps.py Configuration

First, make sure your article/apps.py has the correct name value—this is what Django uses to identify the app internally:

# article/apps.py
from django.apps import AppConfig

class ArticleConfig(AppConfig):
    name = 'article'  # This must match the new app name exactly

If this was still set to block, Django will keep looking for the old module name.

2. Replace All References to block in Your Codebase

Do a quick search across your entire project for any leftover mentions of block and replace them with article:

  • Project URLs: In forum/urls.py, update any include('block.urls') or from block import views lines
  • URL Namespaces: If you used namespaces like {% url 'block:post_detail' %} in templates, change them to {% url 'article:post_detail' %}
  • Model/View Imports: Check other apps (if any) for lines like from block.models import Post and update to from article.models import Post

3. Clear Python Cache Files

Old cache files can hold references to the old app name. Delete all __pycache__ folders in your project:

# Run this from your project root (where manage.py lives)
find . -name "__pycache__" -type d -exec rm -rf {} +

Also, if you're using an IDE like PyCharm or VS Code, restart it—sometimes IDEs cache module paths even after you've renamed files.

4. Restart the Development Server (Properly)

Django's auto-reloader can sometimes hang onto old module data. Stop the server completely with Ctrl+C, then restart it:

python manage.py runserver

5. Verify Migrations (Optional)

Since you already deleted and recreated migrations, this is probably fine, but just to be safe:

python manage.py makemigrations article
python manage.py migrate

That's it! These steps should resolve the module not found error without any complex workarounds.

内容的提问来源于stack exchange,提问作者Wizard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:09:43