Code: it pays the bills fun.
An entire django app in a single file. Updated from here to use Django trunk.
An entire django app in a single file. Updated from here to use Django trunk.
This started off to see what the absolutely smallest requirements needed to run a Django project. Run the pico_django.py with $ PYTHONPATH=. django-admin.py runserver 0.0.0.0:8000 --settings=pico_django and go to http://localhost:8080
from django.http import HttpResponse
from django.conf.urls.defaults import patterns
DEBUG=True
ROOT_URLCONF = 'pico_django'
DATABASES = { 'default': {} }
def index(request, name):
return HttpResponse('Hello {name}!'.format(name=(name or 'World')))
urlpatterns = patterns('', (r'^(?P<name>\w+)?$', index))
Soon pico needed a little more spice, so it got some template loading and then because I'm lazy I made the new version directly runnable.
Run the mini_django.py with $ python ./micro_django.py and go to http://localhost:8000/Foo
import os, sys
from django.conf.urls.defaults import patterns
from django.template.response import TemplateResponse
# this module
me = os.path.splitext(os.path.split(__file__)[1])[0]
# helper function to locate this dir
here = lambda x: os.path.join(os.path.abspath(os.path.dirname(__file__)), x)
# SETTINGS
DEBUG=TEMPLATE_DEBUG=True
ROOT_URLCONF = me
DATABASES = { 'default': {} } #required regardless of actual usage
TEMPLATE_DIRS = (here('.'), )
# VIEW
def index(request, name):
return TemplateResponse(request, 'index.html', {'name': name})
# URLS
urlpatterns = patterns('', (r'^(?P<name>\w+)?$', index))
if __name__=='__main__':
# set the ENV
os.environ['DJANGO_SETTINGS_MODULE'] = me
sys.path += (here('.'),)
# run the development server
from django.core import management
management.call_command('runserver','0.0.0.0:8000' )
wget https://github.com/readevalprint/mini-django/raw/master/mini_django.py$ python ./mini_django.pyAs-is. Public Domain. Don't blame me.
Tim Watts (tim@readevalprint.com)