[Django]-ImportError No module named blog

2👍

you should also take a look at the tutorial included in django docs for the parts that may not be covered in the one you found.

you may need to modify settings.py and add the blog app to INSTALLED_APPS to solve the ImportError. This is covered in the activating models section of the tutorial.

EDIT: here is what seems to be needed to solve the ImportError you had.

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog', # <------ your app here.
     ...
 }
👤dnozay

3👍

I had the very same problem while working through this tutorial from tutsplus. Like user61629 said, you need to change the url pattern to ‘blog.views.home’ instead of ‘FirstBlog.blog.views.home’ and it works perfectly.

👤joe

1👍

Forgetting comas after each INSTALLED_APPS could also cause a similar error. For example:

INSTALLED_APPS = (
    'django.contrib.auth'  <----------- No Comma!
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

(May help a beginner like me out there)

👤kook

0👍

Sounds like a simple import error. Could be due to either you having not installed the app ‘blog’ check your settings.py it is installed?

The other issue could be simply an incorrect import path for example

from blog.models import Blog

Either way it sounds like you should continue reading the docs. I found these video very helpful
http://hackedexistence.com/project-django.html

Also on another note from your code above don’t include full paths like this…

TEMPLATE_DIRS = (
    "F:/firstblog/blog/templates",

It can give you a lot of issues later on.

0👍

It is also a good practice not to use absolute paths like F:/firstblog/blog/templates in your project as if you deploy on the server or other people also develop this project they have to change these paths.

Try using unipath for this or just os module to set paths.

0👍

This error might because you rename your Django project after creation. So you have to undo and go back to the name you use to create the Django project or trace the error and update it with the new Django name.

0👍

I was faced with the same error because I created app outside of the project. Check whether your app is in its right directory or not.

Leave a comment