Django Hello World

  • source env/bin/activate
  • django-admin.py startproject myproject
  • cd myproject
  • python manage.py syncdb
  • python manage.py startapp helloworld
  • vim myproject/urls.py
urlpatterns = patterns('',
    ...
    url(r'^$', 'helloworld.views.main_page'),
)
  • vim helloworld/views.py
#from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def main_page(request):
    output = '''
        <html>
            <title>%s</title>
            <body>
                <h1>%s</h1>
            </body>
        </html>
    ''' % (
        'My Project',
        'Hello World!'
    )
    return HttpResponse(output)