public
Description: Turtles all the way down
Homepage: http://simonwillison.net/2009/May/19/djng/
Clone URL: git://github.com/simonw/djng.git
djng /
name age message
file LICENSE.txt Thu May 28 16:26:41 -0700 2009 Added BSD license [simonw]
directory djng/ Fri Jul 03 17:00:51 -0700 2009 Very basic template support - after umming and ... [simonw]
file djng_old.py Sat May 09 04:24:11 -0700 2009 Started to play around with the concept of serv... [simonw]
file example_forms.py Tue May 12 11:02:36 -0700 2009 Added example of form validation using the Djan... [simonw]
file example_hello.py Mon May 11 10:27:12 -0700 2009 Figured out what hello world should look like i... [simonw]
file example_middleware.py Mon May 18 01:46:30 -0700 2009 Added djng.middleware.GZip and example of apply... [simonw]
file example_rest_view.py Tue May 12 01:44:18 -0700 2009 Example showing how staticmethods can be used t... [simonw]
file example_services_incomplete.py Mon May 11 11:17:13 -0700 2009 De-emphasized the example_app for services that... [simonw]
file example_template.py Fri Jul 03 17:00:51 -0700 2009 Very basic template support - after umming and ... [simonw]
directory example_templates/ Fri Jul 03 17:00:51 -0700 2009 Very basic template support - after umming and ... [simonw]
file example_urls.py Thu May 21 13:44:43 -0700 2009 ErrorWrapper: send correct status code back to ... [peritus]
file planned_services.txt Thu May 14 04:16:51 -0700 2009 URL reversing should be a service [simonw]
file readme.txt Thu May 21 13:44:43 -0700 2009 ErrorWrapper: send correct status code back to ... [peritus]
file services_api_ideas.txt Mon May 18 10:17:31 -0700 2009 Some ideas for how the services API could work [simonw]
file setup.py Thu May 21 13:44:07 -0700 2009 Added a setup.py. Signed-off-by: Simon Williso... [brosner]
readme.txt
djng
====
(pronounced "djing", with a mostly-silent "d")

Blog entry: http://simonwillison.net/2009/May/19/djng/
Mailing list: http://groups.google.com/group/djng

djng is a micro-framework that depends on a macro-framework (Django).

My definition of a micro-framework: something that lets you create an entire
Python web application in a single module:

    import djng
    
    def index(request):
        return djng.Response('Hello, world')
    
    if __name__ == '__main__':
        djng.serve(index, '0.0.0.0', 8888)

Or if you want hello and goodbye URLs, and a custom 404 page:

    import djng

    app = djng.ErrorWrapper(
        djng.Router(
            (r'^hello$', lambda request: djng.Response('Hello, world')),
            (r'^goodbye$', lambda request: djng.Response('Goodbye, world')),
        ),
        custom_404 = lambda request: djng.Response('404 error', status=404),
        custom_500 = lambda request: djng.Response('500 error', status=500)
    )
    
    if __name__ == '__main__':
        djng.serve(app, '0.0.0.0', 8888)

Under the hood, djng will re-use large amounts of functionality from Django,
while re-imagining various aspects of the framework. A djng request object is
a Django HttpRequest object; a djng response object is a Django HttpResponse.
Django's template language and ORM will be available. Ideally, Django code
will run almost entirely unmodified under djng, and vice versa.

Services, not Settings
======================

I dislike Django's settings.py file - I often find I want to reconfigure
settings at run-time, and I'm not comfortable with having arbitrary settings
for so many different aspects of the framework.

djng experiments with /services/ in place of settings. Services are bits of
shared functionality that djng makes available to applications - for example,
caching, templating, ORM-ing and mail-sending.

Most of the stuff that Django sets up in settings.py will in djng be set up by
configuring services. These services will be designed to be reconfigured at
run-time, using a mechanism similar to Django middleware.

Some things that live in settings.py that really don't belong there -
middleware for example. These will generally be constructed by composing
together a djng application in code.

I'm still figuring out how the syntax for services should work.