Django "No Module Named URLs" error

Let's say I have a Django project called FailBook, with two apps, posts and links. If I look into FailBook/urls.py, I will find something like

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),

    url(r'^posts/', include('posts.urls')), ## Custom url include
    url(r'^links/', include('links.urls')), ## Custom url include
)

So then, when you look into the directory structure, you will notice that there are extra two urls.py files

FailBook
|-- posts
   |-- models.py
   |-- urls.py
   |-- views.py
   |-- etc.
|-- links
   |-- models.py
   |-- urls.py
   |-- views.py
   |-- etc.

# urls.py file in the posts folder
from django.conf.urls import patterns, include, url
from .views import PostListView, PostDetailView

urlpatterns = patterns('',

    url(r'^posts/', PostListView.as_view()), 
    url(r'^posts/(?P<post_id>\d+)', PostDetailView.as_view()),
)
# where both views are class based views, hence the as_view function call

I know this was already solved, but the solutions provided did not help me. When I had this error it was as simple as checking all of the directories that should have had urls.py files.What I discovered was that the urls.py had not been added to the SVN repository that our Django app was pulled from.

I recommend looking in the projectname->projectname->urls.py for all references to app specific urls, and verifying that the urls.py file exists for each of them.

Tags:

Python

Django