Quiet runserver

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from django.conf import settings
from django.core.servers import basehttp
from django.core.management.commands.runserver import Command as BaseCommand

class QuietWSGIRequestHandler(basehttp.WSGIRequestHandler):
    def log_message(self, format, *args):
        # Don't bother logging requests for paths under MEDIA_URL.
        if self.path.startswith(settings.MEDIA_URL):
            return
        # can't use super as base is old-style class, so call method explicitly
        return basehttp.WSGIRequestHandler.log_message(self, format, *args)
    
def run(addr, port, wsgi_handler):
    server_address = (addr, port)
    httpd = basehttp.WSGIServer(server_address, QuietWSGIRequestHandler)
    httpd.set_app(wsgi_handler)
    httpd.serve_forever()
    
class Command(BaseCommand):
    def handle(self, addrport='', *args, **options):
        # monkeypatch Django to use our quiet server
        basehttp.run = run
        return super(Command, self).handle(addrport, *args, **options)

More like this

  1. Serve admin-media from urls.py by wolever 1 year, 9 months ago
  2. collectmedia command: Copy or link media files from installed apps by exogen 4 years, 9 months ago
  3. pyserver -- runserver alias by presclark 5 years, 1 month ago
  4. Continuous Integration command by berto 3 years, 8 months ago
  5. Link Media Command by elwaywitvac 4 years, 9 months ago

Comments

d-rave (on June 15, 2010):

Also works in you put the file with django's 'built-in' commands :-

django/core/management/commands/

#

(Forgotten your password?)