Created
May 5, 2011 04:29
-
-
Save readevalprint/956544 to your computer and use it in GitHub Desktop.
The minimalist versions of django. One file. Read more at readevalprint.com/mini-django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Hey {{name|default:"there"}}!</title> | |
</head> | |
<body> | |
It's a lovely day, eh {{name|default:"chap"}}? | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Run this 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' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
# run with djagno dev server | |
# $ PYTHONPATH=. django-admin.py runserver 0.0.0.0:8000 --settings=pico_django | |
# for example run with uwsgi | |
# $ uwsgi -s 127.0.0.1:3031 -M --pythonpath=/path/to/this/dir --env DJANGO_SETTINGS_MODULE=pico_django -w "django.core.handlers.wsgi:WSGIHandler()" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment