update to reflect API changes
[gae-samples.git] / django_example / django_bootstrap.py
blob961c30295478d649dc8bd27088fb7853f52b7043
1 # Copyright 2008 Google Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 """Bootstrap for running a Django app under Google App Engine.
18 The site-specific code is all in other files: settings.py, urls.py,
19 models.py, views.py. And in fact, only 'settings' is referenced here
20 directly -- everything else is controlled from there.
22 """
24 # Standard Python imports.
25 import os
26 import sys
27 import logging
28 import __builtin__
30 # Google App Hosting imports.
31 from google.appengine.ext.webapp import util
33 import pickle
34 sys.modules['cPickle'] = pickle
36 # Enable info logging by the app (this is separate from appserver's
37 # logging).
38 logging.getLogger().setLevel(logging.INFO)
40 # Force sys.path to have our own directory first, so we can import from it.
41 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
43 # Must set this env var *before* importing any part of Django.
44 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
46 # Make sure we can import Django. We may end up needing to do this
47 # little dance, courtesy of Google third-party versioning hacks. Note
48 # that this patches up sys.modules, so all other code can just use
49 # "from django import forms" etc.
50 try:
51 from django import v0_96 as django
52 except ImportError:
53 pass
55 # Import the part of Django that we use here.
56 import django.core.handlers.wsgi
58 def main():
59 # Create a Django application for WSGI.
60 application = django.core.handlers.wsgi.WSGIHandler()
62 # Run the WSGI CGI handler with that application.
63 util.run_wsgi_app(application)
65 if __name__ == '__main__':
66 main()