sam
sam

Reputation: 655

ImportError No module named views

I am very new to Django. I just configured it and trying to create a simple Hello world! web application. I am following a tutorial step by step. I ran the command python django-admin.py startproject mysite which created mysite directory with another directory called mysite in it along witbh manage.py. The sub directory mysite has init.py init.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc.

In the outer mysite directory I created views.py which has the following code:-

from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello world!")

In the inner mysite directory, in urls.py I have the following code:-

from django.conf.urls import patterns, include, url
from mysite.views import *

urlpatterns = patterns('',
    url(r'^hello/$', 'mysite.views.hello'),

But I am getting this error:-

ImportError at /hello/

No module named views

Request Method:     GET
Django Version:     1.6.2
Exception Type:     ImportError
Exception Value:    

No module named views

Exception Location:     /data/aman/mysite/mysite/urls.py in <module>, line 2
Python Executable:  /usr/bin/python
Python Version:     2.6.6
Python Path:    

['/data/aman/mysite',
 '/usr/lib64/python26.zip',
 '/usr/lib64/python2.6',
 '/usr/lib64/python2.6/plat-linux2',
 '/usr/lib64/python2.6/lib-tk',
 '/usr/lib64/python2.6/lib-old',
 '/usr/lib64/python2.6/lib-dynload',
 '/usr/lib64/python2.6/site-packages',
 '/usr/lib/python2.6/site-packages']

Server time:    Tue, 25 Feb 2014 10:27:38 +0000

Upvotes: 2

Views: 11740

Answers (2)

Thom
Thom

Reputation: 1623

Usually it is not a best practice to do from ... import * try this:

from django.conf.urls import patterns, include, url
from mysite.views import hello

urlpatterns = patterns('',
    url(r'^hello/$', hello),

Upvotes: 4

Mathieu Dhondt
Mathieu Dhondt

Reputation: 8914

Try and move views.py to the "inner" mysite directory. Views are part of an application, hence the need to move them inside the application directory (and not in the project directory).

The error message you get indicates that mysite(the application) has no views.py module.

Upvotes: 5

Related Questions