Django Hello World Project

Create Django Project -

$ django-admin.py startproject DJangoSample

Following directories created -

$ tree .
.
├── DJangoSample
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── wsgi.py
│   └── wsgi.pyc
└── manage.py

1 directory, 8 files

Verify this worked. Run server -

$ python manage.py runserver
Validating models...

0 errors found
May 28, 2013 - 23:27:52
Django version 1.5.1, using settings 'DJangoSample.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Run in different port -

python manage.py runserver 6969

visit :-)

http://127.0.0.1:8000/

Let's create Hello World things :-)

Create views.py -

from django.http import HttpResponse
 
def hello(request):
    return HttpResponse("Hello World :-)")

Edit dispatcher file - urls.py

from django.conf.urls.defaults import patterns, include, url
from DJangoSample.views import hello
 
urlpatterns = patterns('',
    url(r'^hello/$', hello),
)

Restart server - old school part :-)

python manage.py runserver

voila :-)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License