2
votes

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
2

2 Answers

5
votes

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.

4
votes

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