My favorites
▼
|
Sign in
googleappengine
Google App Engine
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
python
/
google
/
appengine
/
ext
/
webapp
/
__init__.py
‹r257
r265
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""An extremely simple WSGI web application framework.
This module is an alias for the webapp2 module i.e. the following are
equivalent:
1. from google.appengine.ext import webapp
2. import webapp2 as webapp
It exports three primary classes: Request, Response, and RequestHandler. You
implement a web application by subclassing RequestHandler. As WSGI requests come
in, they are passed to instances of your RequestHandlers. The RequestHandler
class provides access to the easy-to-use Request and Response objects so you can
interpret the request and write the response with no knowledge of the esoteric
WSGI semantics. Here is a simple example:
from google.appengine.ext import webapp
import wsgiref.simple_server
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write(
'<html><body><form action="/hello" method="post">'
'Name: <input name="name" type="text" size="20"> '
'<input type="submit" value="Say Hello"></form></body></html>')
class HelloPage(webapp.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, %s' % self.request.get('name'))
application = webapp.WSGIApplication([
('/', MainPage),
('/hello', HelloPage)
], debug=True)
The WSGIApplication class maps URI regular expressions to your RequestHandler
classes. It is a WSGI-compatible application object, so you can use it in
conjunction with wsgiref to make your web application into, e.g., a CGI
script or a simple HTTP server, as in the example above.
The framework does not support streaming output. All output from a response
is stored in memory before it is written.
"""
import logging
import os
from google.appengine.api import lib_config
def __django_version_setup():
"""Selects a particular Django version to load."""
django_version = _config_handle.django_version
if django_version is not None:
from google.appengine.dist import use_library
use_library('django', str(django_version))
else:
from google.appengine.dist import _library
version, explicit = _library.installed.get('django', ('0.96', False))
if not explicit:
logging.warn('You are using the default Django version (%s). '
'The default Django version will change in an '
'App Engine release in the near future. '
'Please call use_library() to explicitly select a '
'Django version. '
'For more information see %s',
version,
'https://developers.google.com/appengine/docs/python/tools/'
'libraries#Django')
try:
import django
if not hasattr(django, 'VERSION'):
from django import v0_96
except ImportError:
pass
def _django_setup():
"""Imports and configures Django.
This can be overridden by defining a function named
webapp_django_setup() in the app's appengine_config.py file (see
lib_config docs). Such a function should import and configure
Django.
In the Python 2.5 runtime, you can also just configure the Django version to
be used by setting webapp_django_version in that file.
Finally, calling use_library('django', <version>) in that file
should also work:
# Example taken from from
# https://developers.google.com/appengine/docs/python/tools/libraries#Django
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')
In the Python 2.7 runtime, the Django version is specified in you app.yaml
file and use_library is not supported.
If your application also imports Django directly it should ensure
that the same code is executed before your app imports Django
(directly or indirectly). Perhaps the simplest way to ensure that
is to include the following in your main.py (and in each alternate
main script):
from google.appengine.ext.webapp import template
import django
This will ensure that whatever Django setup code you have included
in appengine_config.py is executed, as a side effect of importing
the webapp.template module.
"""
if os.environ.get('APPENGINE_RUNTIME') != 'python27':
__django_version_setup()
import django
import django.conf
try:
getattr(django.conf.settings, 'FAKE_ATTR', None)
except (ImportError, EnvironmentError), e:
if os.getenv(django.conf.ENVIRONMENT_VARIABLE):
logging.warning(e)
try:
django.conf.settings.configure(
DEBUG=False,
TEMPLATE_DEBUG=False,
TEMPLATE_LOADERS=(
'django.template.loaders.filesystem.load_template_source',
),
)
except (EnvironmentError, RuntimeError):
pass
if os.environ.get('APPENGINE_RUNTIME') == 'python27':
_config_handle = lib_config.register(
'webapp',
{'add_wsgi_middleware': lambda app: app,})
from webapp2 import *
else:
_config_handle = lib_config.register(
'webapp',
{'django_setup': _django_setup,
'django_version': None,
'add_wsgi_middleware': lambda app: app,
})
from google.appengine.ext.webapp._webapp25 import *
from google.appengine.ext.webapp._webapp25 import __doc__
Show details
Hide details
Change log
r262
by mar...@google.com on May 22 (5 days ago)
Diff
[No log message]
Go to:
/trunk/python/README
/trunk/python/RELEASE_NOTES
/trunk/python/VERSION
/trunk/python/api_server.py
/trunk/python/appcfg.py
/trunk/python/bulkload_client.py
/trunk/python/bulkloader.py
/trunk/python/dev_appserver.py
/trunk/python/download_appstats.py
/trunk/python/gen_protorpc.py
...e/appengine/api/apiproxy_stub.py
...pengine/api/apiproxy_stub_map.py
.../google/appengine/api/appinfo.py
...gle/appengine/api/backendinfo.py
.../capabilities/capability_stub.py
...appengine/api/channel/channel.py
...pi/channel/channel_service_pb.py
.../channel/channel_service_stub.py
...hon/google/appengine/api/conf.py
...google/appengine/api/croninfo.py
...oogle/appengine/api/datastore.py
...appengine/api/datastore_types.py
.../google/appengine/api/dosinfo.py
...ogle/appengine/api/files/file.py
...e/api/files/file_service_stub.py
...ine/api/logservice/logservice.py
...pengine/api/memcache/__init__.py
...ne/api/memcache/memcache_stub.py
...appengine/api/oauth/oauth_api.py
...e/appengine/api/pagespeedinfo.py
...oogle/appengine/api/queueinfo.py
...appengine/api/search/__init__.py
...e/appengine/api/search/search.py
.../api/search/search_service_pb.py
...ngine/api/taskqueue/taskqueue.py
...e/appengine/api/urlfetch_stub.py
...pengine/api/user_service_stub.py
...gine/api/xmpp/xmpp_service_pb.py
...ne/api/xmpp/xmpp_service_stub.py
...ne/cron/groctimespecification.py
...le/appengine/datastore/acl_pb.py
...ine/datastore/datastore_index.py
...tastore/datastore_sqlite_stub.py
...datastore/datastore_stub_util.py
...pengine/datastore/document_pb.py
...appengine/datastore/entity_pb.py
.../appengine/ext/admin/__init__.py
...min/datastore_stats_generator.py
...templates/datastore_indexes.html
...n/templates/datastore_stats.html
Older revisions
r257
by mar...@google.com on Apr 25, 2012
Diff
[No log message]
r216
by mar...@google.com on Nov 7, 2011
Diff
[No log message]
r199
by mar...@google.com on Sep 12, 2011
Diff
[No log message]
All revisions of this file
File info
Size: 5928 bytes, 203 lines
View raw file
File properties
svn:executable
*
Powered by
Google Project Hosting