Reputation: 93
A lot of other people have come across the error No module named <appname>
. However. I couldn't relate to the problem they had. I tried to run manage.py shell and then imported the app (blog). It worked. So what is wrong in my code?
urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'projectname.blog.views.index', name = 'index')
]
settings.py:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
)
views.py:
from django.shortcuts import render
from blog.models import posts
def home(request):
return render('index.html', {'title': 'My First Post'})
Error message:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.8.5
Exception Type: ImportError
Exception Value:
No module named blog
Exception Location: /usr/lib/python2.7/importlib/__init__.py in import_module, line 37
Python Executable: /usr/bin/python
Python Version: 2.7.6
Upvotes: 0
Views: 2364
Reputation: 1
In your views.py you were defined the home instead of index Try below one
def index(request):
return render('index.html', {'title': 'My First Post'})
Upvotes: 0
Reputation: 27102
A couple of issues:
projectname
home
, not index
Therefore, you should be using:
url(r'^$', 'blog.views.home', name='index')
Upvotes: 4
Reputation: 1194
Don't use your project name in path to specific app. Instead of
url(r'^$', 'projectname.blog.views.index', name = 'index')
use
url(r'^$', 'blog.views.index', name = 'index')
Upvotes: 0