Changeset 185
- Timestamp:
- 07/18/05 17:35:04 (3 years ago)
- Files:
-
- django/trunk/django/bin/django-admin.py (modified) (2 diffs)
- django/trunk/django/conf/admin_media (moved) (moved from django/trunk/media)
- django/trunk/django/core/handlers/wsgi.py (modified) (1 diff)
- django/trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/bin/django-admin.py
r174 r185 366 366 "Starts a lightweight Web server for development." 367 367 from django.core.servers.basehttp import run, WSGIServerException 368 from django.core.handlers.wsgi import WSGIHandler368 from django.core.handlers.wsgi import AdminMediaHandler, WSGIHandler 369 369 if not port.isdigit(): 370 370 sys.stderr.write("Error: %r is not a valid port number.\n" % port) … … 372 372 print "Starting server on port %s. Go to http://127.0.0.1:%s/ for Django." % (port, port) 373 373 try: 374 run(int(port), WSGIHandler())374 run(int(port), AdminMediaHandler(WSGIHandler())) 375 375 except WSGIServerException, e: 376 376 # Use helpful error messages instead of ugly tracebacks. django/trunk/django/core/handlers/wsgi.py
r169 r185 241 241 import sys, traceback 242 242 return '\n'.join(traceback.format_exception(*sys.exc_info())) 243 244 class AdminMediaHandler: 245 """ 246 WSGI middleware that intercepts calls to the admin media directory, as 247 defined by the ADMIN_MEDIA_PREFIX setting, and serves those images. 248 Use this ONLY LOCALLY, for development! This hasn't been tested for 249 security and is not super efficient. 250 """ 251 def __init__(self, application): 252 from django.conf import settings 253 import django 254 self.application = application 255 self.media_dir = django.__path__[0] + '/conf/admin_templates' 256 self.media_url = settings.ADMIN_MEDIA_PREFIX 257 258 def __call__(self, environ, start_response): 259 import os.path 260 261 # Ignore requests that aren't under ADMIN_MEDIA_PREFIX. 262 if not environ['PATH_INFO'].startswith(self.media_url): 263 return self.application(environ, start_response) 264 265 # Find the admin file and serve it up, if it exists and is readable. 266 file_path = os.path.join(self.media_dir, environ['PATH_INFO'][1:]) 267 if not os.path.exists(file_path): 268 status = '404 NOT FOUND' 269 headers = {'Content-type': 'text/plain'} 270 output = ['Page not found: %s' % file_path] 271 else: 272 try: 273 fp = open(file_path, 'r') 274 except IOError: 275 status = '401 UNAUTHORIZED' 276 headers = {'Content-type': 'text/plain'} 277 output = ['Permission denied: %s' % file_path] 278 else: 279 status = '200 OK' 280 headers = {} 281 output = [fp.read()] 282 fp.close() 283 start_response(status, headers.items()) 284 return output django/trunk/setup.py
r155 r185 14 14 packages = find_packages(), 15 15 package_data = { 16 'django.conf': ['admin_templates/*.html', 'admin_templates/doc/*.html'], 16 'django.conf': ['admin_templates/*.html', 'admin_templates/doc/*.html', 17 'admin_media/css/*.css', 'admin_media/img/admin/*.gif', 18 'admin_media/img/admin/*.png', 'admin_media/js/*.js', 19 'admin_media/js/admin/*js'], 17 20 }, 18 21 scripts = ['django/bin/django-admin.py'],
