0

So I'm following a tutorial from programmersbook.com and I'm at a point where I've finished the 7th video located here http://www.youtube.com/watch?v=hTq98PGOqMA&feature=share&list=PL385A53B00B8B158E.

After passing the command to ./manage.py runserver I'm getting the following error.

ImportError at /admin/

No module named apps.homepage

Below are the contents of the files and a directory structure if needed.

blog/blog/urls.py

from django.conf.urls import patterns, include, url
from blog.apps.homepage import *

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    (r'^', include('blog.apps.homepage.urls')),
    # Examples:
    # url(r'^$', 'blog.views.home', name='home'),
    # url(r'^blog/', include('blog.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)

blog/apps/homepage/urls.py

  from django.conf.urls.defaults import *

  urlpatterns = patterns('',
      (r'^$', 'blog.apps.homepage.views.index'),
  )

blog/apps/homepage/views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse('Index Page')

Just in case it's needed here's my file and directory structure

blog
├── apps
│   ├── homepage
│   │   ├── __init__.py
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   └── __init__.py
├── blog
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── custom
│   └── __init__.py
├── data.db
├── manage.py
├── static
│   ├── css
│   ├── img
│   ├── js
│   ├── restricted
│   └── upload
└── templates

Could someone help me understand what I can do to fix this error?

2
  • What's the content of apps/__init__.py and what do you have in INSTALLED_APPS of settings.py? Dec 28, 2012 at 22:08
  • @thierry-lam The content of apps/__init__.py is empty and from what I've been told that's correct. Does it need to have something in there? INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'apps.homepage', )
    – user1940321
    Dec 28, 2012 at 22:10

2 Answers 2

2

It's recommended to not include your project name blog across your django project. Modify the following:

blog/blog/urls.py

urlpatterns = patterns('',
    url(r'^', include('apps.homepage.urls')),
)

blog/apps/homepage/urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^$', 'apps.homepage.views.index'),
)
1
  • Awesome..That fixed it! Thanks! I'm guessing it's probably an outdated video I'm attempting to work through that had an old way of doing this by passing in the project name. I'll keep that in mind when working through the rest of the video.
    – user1940321
    Dec 28, 2012 at 22:33
0

In blog/urls.py, try geting rid of "from blog.apps.homepage import *"

I checked the linked documentation, and that line does not appear there. Also, if you look at your file structure, this line is importing files, not entities within the file. Normally, you'd use the "from x.y.z import *" to import, say, all the models in a models file. May be that you're getting namespace conflicts or something like that by importing all those files.

Maybe also try putting "homepage" instead of "apps.homepage" in your INSTALLED_APPS in settings.py. Given the error you're getting, i'm inclined to think this is where the problem lies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.