Importerror (djangobook Chapter 3, Part1, Python Version 2.7.2)
Solution 1:
Update: fully working with Django 1.4.0-final
Overall, I'd recommend to re-do the startproject
step and start over from scratch; I will summarize the steps you need to take:
1) Create a new Django project
$ django-admin.py startproject helloWorldProject
This creates a new folder helloWorldProject
containing some stub files.
2) Create a new file views.py
_INSIDE_ your helloWorldProject/helloWorldProject
folder. It should contain the following code:
from django.http import HttpResponse
defhello(request):
return HttpResponse("Hello world")
3) Update the urls.py
file (within the same folder as views.py
):
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
url(r'^$', 'helloWorldProject.views.hello', name='hello'),
)
4) Run your server using the known command:
$ python manage.py runserver
This should give you some output similar to this
Validating models...
0 errors found
Django version 1.4, using settings 'helloWorldProject.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
5) Check if your "Hello World" view works -- point your browser to http://127.0.0.1:8000/
NOTE: If you define an URL pattern like ('^hello/$', 'helloWorldProject.views.hello', name='hello'),
, you have to point your browser to http://127.0.0.1:8000/hello/ as otherwise you will get an HTTP 404 error message...
Hope that helps :)
Solution 2:
Django book describes old django version. Quote from Chapter 2
Official releases have a version number, such as 1.0.3 or 1.1, and the latest one is always available at http://www.djangoproject.com/download/.
In the newest 1.4 project layout was updated, so be careful to use examples from that book. I advise you to try tutorial from official documentation at first.
I assume you should create views.py
in ~Desktop/sc/mysite2/mysite2
near urls.py
Post a Comment for "Importerror (djangobook Chapter 3, Part1, Python Version 2.7.2)"