import mimetypes
import posixpath
import urllib

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.contrib.staticfiles.views import serve as staticfiles_serve
from django.http import HttpResponse

from gears.assets import build_asset
from .settings import environment


def serve(request, path, **kwargs):
    if not settings.DEBUG and not kwargs.get('insecure'):
        raise ImproperlyConfigured(
            "The gears view can only be used in debug mode or if the "
            "--insecure option of 'runserver' is used.")
    normalized_path = posixpath.normpath(urllib.unquote(path)).lstrip('/')
    asset = build_asset(environment, normalized_path)
    if not asset:
        return staticfiles_serve(request, path, **kwargs)
    mimetype, encoding = mimetypes.guess_type(normalized_path)
    mimetype = mimetype or 'application/octet-stream'
    response = HttpResponse(asset, mimetype=mimetype)
    if encoding:
        response['Content-Encoding'] = encoding
    return response

@@ -278,16 +278,59 @@
 d_asset%0A
+from gears.exceptions import FileNotFound%0A%0A
 from .se
@@ -690,16 +690,29 @@
 ip('/')%0A
+    try:%0A    
     asse
@@ -765,20 +765,27 @@
     
-if not asset
+except FileNotFound
 :%0A  

Handle FileNotFound exception from build_asset