Example #1
0
from django.http import Http404

from jsurls import utils

handlers = utils.load_from_staticfiles('handlers')
StaticFilesHandler = getattr(handlers, 'StaticFilesHandler', object)


class JsUrlsStaticFilesHandler(StaticFilesHandler):

    @classmethod
    def replacestatic(cls, handler):
        if StaticFilesHandler is not object and isinstance(handler, StaticFilesHandler):
            return cls(handler.application, handler.base_dir)
        return handler

    def get_response(self, request):
        if self._should_handle(request.path):
            try:
                return self.serve(request)
            except Http404:
                pass # Don't 404 eagerly
        return super(StaticFilesHandler, self).get_response(request)
Example #2
0
from __future__ import absolute_import

from django.core.management.commands.runserver import Command as RunserverCommand

from jsurls import utils
from jsurls.handlers import JsUrlsStaticFilesHandler


runserver = utils.load_from_staticfiles('management.commands.runserver')
StaticFilesRunserverCommand = getattr(runserver, 'Command', None)


class Command(StaticFilesRunserverCommand or RunserverCommand):

    def get_handler(self, *args, **options):
        handler = super(Command, self).get_handler(*args, **options)
        return JsUrlsStaticFilesHandler.replacestatic(handler)