john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

django helloworld hi

# follow the usual steps to install python 2.7.3 and django 1.4.2 , then setup a project and app:

django-admin.py startproject helloworld

chmod +x helloworld/manage.py

helloworld/manage.py startapp hi

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vi helloworld/helloworld/settings.py

...

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',

    'hi',
)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# note this handles two different URL patterns: 192.168.1.2/ and 192.168.1.2/hi
# when the regex is empty or "begins with hi" then it returns the function index from the view in the hello application

from django.conf.urls import patterns, include, url

urlpatterns = patterns('',
    (r'^$','hi.views.index'),
    (r'^hi','hello.views.index'),
)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vi helloworld/hi/views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("hi")


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You can verify the python django app is running using the dev web engine
./manage.py runserver 0.0.0.0:8888

  • « maven multi module project
  • maven servlet parameters echo »

Published

Dec 2, 2012

Category

python

~123 words

Tags

  • django 5
  • helloworld 1
  • hi 1
  • python 180