Django doesn’t really need a hello world style introduction, its documentation speaks for itself.
But this is what “Hello, world!” in Django looks like to me. I hate boilerplate and I love reducing software down to its core components; just enough to start the server.
setup.py:
from setuptools import setup
setup(
name='hello',
)
requirements.txt:
Django==1.4.1
-e .
settings.py:
from hello import urls
DEBUG = True
ROOT_URLCONF = urls
urls.py:
from django.conf.urls import patterns
urlpatterns = patterns(
'',
(r'', 'hello.views.index'),
)
views.py:
from django.http import HttpResponse
import datetime
# Based on https://docs.djangoproject.com/en/1.4/topics/http/views/
def index(request):
"""
This function takes a Django request object and returns a 'Hello World'
style response, by wrapping some HTML in a Django response object.
"""
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
Installation
To install:
$ git clone this-repo
$ cd this-repo
$ virtualenv .
$ bin/pip install -r requirements.txt
$ bin/django-admin.py runserver --settings=hello.settings
The above code can be found here: https://github.com/aclark4life/django-hello
Consider a
<3