[Fixed]-Django says – No module named 'blog'

14πŸ‘

βœ…

Django needs to be able to import your application, usually this means including the full path relative to the root directory 'myproject.blog'.

You could add <full_path_to_your_project>/myproject/myproject to PYTHONPATH so that you can import blog, but I would not recommend it

20πŸ‘

Directory structure is unusual. More usual and the one that matches your app being named blog would be

myproject/
β”œβ”€β”€ myproject
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ __pycache__
β”‚   β”‚   β”œβ”€β”€ __init__.cpython-36.pyc
β”‚   β”‚   β”œβ”€β”€ settings.cpython-36.pyc
β”‚   β”‚   β”œβ”€β”€ urls.cpython-36.pyc
β”‚   β”‚   └── wsgi.cpython-36.pyc
β”œβ”€β”€ blog
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ admin.py
β”‚   β”œβ”€β”€ apps.py
β”‚   β”œβ”€β”€ migrations
β”‚   β”‚   └── __init__.py
β”‚   β”œβ”€β”€ models.py
β”‚   β”œβ”€β”€ tests.py
β”‚   └── views.py
β”‚   β”œβ”€β”€ settings.py
β”‚   β”œβ”€β”€ urls.py
β”‚   └── wsgi.py
β”œβ”€β”€ db.sqlite3
└── manage.py
πŸ‘€e4c5

0πŸ‘

My problem is solved by adding the path of the app in the settings.py of myproject in this below format

INSTALLED_APPS = [
'blog.apps.BlogConfig', # <app_name>.apps.<class_name>
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',  ]
πŸ‘€Vijay Sai

0πŸ‘

I had a similar issue .Turns out I had already registered my app in the settings.py before running β€˜python manage.py startapp #myapp.

πŸ‘€John Kahura

-2πŸ‘

I usually add the config path to installed apps to avoid this problem. So installed apps would look like this:

NSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog,apps.BlogConfig',
πŸ‘€ckroutz

Leave a comment