1個のファイルでDjangoを動かしてみた。
うまくハックすれば、もっときれいに書けると思うんだけど。
このファイルはmanage.pyの機能を持ってて、mod_wsgiでデプロイもできる。
__init__.py
#!/usr/bin/env python import os import sys BASE_DIR = os.path.dirname(os.path.abspath(__file__)) PROJECT_DIR = os.path.dirname(BASE_DIR) PROJECT_NAME = os.path.basename(BASE_DIR) SETTINGS_MODULE = PROJECT_NAME + '.__init__' os.environ['DJANGO_SETTINGS_MODULE'] = PROJECT_NAME + '.' + SETTINGS_MODULE if not PROJECT_DIR in sys.path: sys.path.append(PROJECT_DIR) if not BASE_DIR in sys.path: sys.path.append(BASE_DIR) from django.conf import global_settings from django.conf.urls.defaults import * from django.http import HttpResponse settings = __import__(SETTINGS_MODULE) DEBUG = True DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = os.path.join(BASE_DIR, 'hoge.db') TEST_RUNNER = SETTINGS_MODULE + '.run_tests' ROOT_URLCONF = '__init__' INSTALLED_APPS = ( PROJECT_NAME, ) def index(request): return HttpResponse('Hello world!') urlpatterns = patterns('', url(r'^$', index), ) if __name__ == "__main__": from django.core.management import execute_manager execute_manager(settings) from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler()