ImportError No module named blog

I am working on 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 added:

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

      

What is the full path.

I am 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:\python27\lib\site-packages\django\utils\importlib.py in            import_module, line 35
Python Executable:  f:\python27\python.exe
Python Version: 2.7.3

      

My installed apps:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

      

I would appreciate any advice on how to fix this,

Thank,

Bill

+3


source to share


5 answers


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

you may need to modify settings.py

and add the app blog

in INSTALLED_APPS

for the solution ImportError

. This is described in the section on activating models in the tutorial.



EDIT: here's what you need for the solution 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.
     ...
 }

      

+1


source


I had the same problem while working on this tutsplus tutorial. Like user61629 you need to change the url pattern to "blog.views.home" instead of "FirstBlog.blog.views.home" and it works great.



+3


source


Sounds like a simple import error. Perhaps because you haven't installed the blog app, check your settings.py, is it installed?

Another problem might just be the wrong import path like

from blog.models import Blog

      

In any case, it looks like you should continue reading the docs. I found this video very helpful http://hackedexistence.com/project-django.html

Also another note from your code above doesn't list full paths like this ...

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

      

This can give you a lot of problems later on.

0


source


It is also a good idea to use absolute paths like F:/firstblog/blog/templates

in your project, as if you were deploying to server or other people developing this project as well, they should change those paths.

Try to use unipath

for this or just os

to set paths.

0


source


Forgetting the commas after each INSTALLED_APPS can also lead to 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',

      

(Can help a newbie like me there)

0


source







All Articles