How to Solve Django Error Message : AttributeError:’module’ object has no attribute ‘attribute_name’

Posted on

This is another article regarding on the error message triggered. The error itself is triggered upon executing a page which is accessed from an URL of a web-based page powered by Django framework. This is happened because of the attribute named ‘home’ doesn’t exist. Below is the actual error message shown :

AttributeError: 'module' object has no attribute 'home'

Because of the error triggered above, the page is not loaded as shown in the following image :

How to Solve Django Error Message : AttributeError:'module' object has no attribute 'attribute_name'
How to Solve Django Error Message : AttributeError:’module’ object has no attribute ‘attribute_name’


As it can be shown in the above image, because of the error , the page cannot be loaded at all. It is unavoidable since it is considered an error which is failing the execution of the page. Certainly it cannot be accessed since the page which is being accessed is a home page. In the home page, the URL is being processed by the URL definition in the file named It is located in the folder of the main project. Below is the description of the location :

user@hostname:~/myproject/apps$ tree -L 3 .
├── bin
├── include
├── lib
...├── local
├── src
│   ├── db.sqlite3
│   ├── apps
│   │   ├──
│   │   ├── __init__.pyc
│   │   ├──
│   │   ├── settings.pyc
│   │   ├──
│   │   ├── urls.pyc
│   │   ├──
│   │   └── wsgi.pyc
│   ├──
│   └── contact
│   ├──
│   ├── admin.pyc
│   ├──
│   ├──
│   ├── __init__.pyc
│   ├── migrations
│   ├──
│   ├── models.pyc
│   ├── templates
│   ├──
│   ├──
│   └── views.pyc
└── xxx

28 directories, 90 files

Considered the project named is ‘myproject’ based on the above output. The application which is considered as a module in the above context is contact. So, based on the error generated which is presented in the previous section of this article, the module named ‘contact’ doesn’t have any attribute named ‘home’. It is obvious since the URL definition on the url file named located in the directory as shown in the tree command output generated named ‘contact’ exist. It is shown as follows :

from contact import views

urlpatterns = [
url(r'^$', views.home, name='home'),

But the attribute as shown in the url defined, the attribute ‘home’ which is expected is there from the imported from the module named ‘apps’ doesn’t exist. Below is the content of the located in the folder named ‘contact’ :

from django.shortcuts import render

# Create your views here.

To solve the problem, just add a new definition or attribute named ‘home’ inside the file named ‘’ as shown below :

def home(request):
    context = locals()
    template = 'home.html'
    return render(request,template,context)

Try to load the home page again off course with the additional action by creating a folder named templates and also a file named ‘home.html’ inside of it.

Leave a Reply