ImportError No module named blog
Question:
I’m working my way through a django tutorial http://net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/ . Following the directions in the template section, I have added:
TEMPLATE_DIRS = (
"F:/firstblog/blog/templates",
Which is the full path.
I’m getting the following error output:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4.3
Exception Type: ImportError
Exception Value:
No module named blog
Exception Location: f:python27libsite-packagesdjangoutilsimportlib.py in import_module, line 35
Python Executable: f:python27python.exe
Python Version: 2.7.3
My installed apps are:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
I’d appreciate any advice on how to fix this,
Thank you,
Bill
Answers:
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.
...
}
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.
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.
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.
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)
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.
faced with the same error ,because I created app outside of the project ♂️ .check whether your app is in its right directory or not.
I’m working my way through a django tutorial http://net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/ . Following the directions in the template section, I have added:
TEMPLATE_DIRS = (
"F:/firstblog/blog/templates",
Which is the full path.
I’m getting the following error output:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4.3
Exception Type: ImportError
Exception Value:
No module named blog
Exception Location: f:python27libsite-packagesdjangoutilsimportlib.py in import_module, line 35
Python Executable: f:python27python.exe
Python Version: 2.7.3
My installed apps are:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
I’d appreciate any advice on how to fix this,
Thank you,
Bill
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.
...
}
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.
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.
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.
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)
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.
faced with the same error ,because I created app outside of the project ♂️ .check whether your app is in its right directory or not.