user1940321
user1940321

Reputation:

Django: Error No module named apps.homepage

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?

Upvotes: 0

Views: 1033

Answers (2)

Thierry Lam
Thierry Lam

Reputation: 46284

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'),
)

Upvotes: 2

Benjamin White
Benjamin White

Reputation: 779

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.

Upvotes: 0

Related Questions