{"record":{"id":"cd40915d7c4bf072","repo":"django/django","slug":"directory-indexes-are-not-allowed-here","errorCode":null,"errorMessage":"Directory indexes are not allowed here.","messagePattern":"Directory indexes are not allowed here\\.","errorType":"http","errorClass":"Http404","httpStatus":404,"severity":"warning","filePath":"django/contrib/staticfiles/views.py","lineNumber":37,"sourceCode":"    from locations inferred from the staticfiles finders.\n\n    To use, put a URL pattern such as::\n\n        from django.contrib.staticfiles import views\n\n        path('<path:path>', views.serve)\n\n    in your URLconf.\n\n    It uses the django.views.static.serve() view to serve the found files.\n    \"\"\"\n    if not settings.DEBUG and not insecure:\n        raise Http404\n    normalized_path = posixpath.normpath(path).lstrip(\"/\")\n    absolute_path = finders.find(normalized_path)\n    if not absolute_path:\n        if path.endswith(\"/\") or path == \"\":\n            raise Http404(\"Directory indexes are not allowed here.\")\n        raise Http404(\"'%s' could not be found\" % path)\n    document_root, path = os.path.split(absolute_path)\n    return static.serve(request, path, document_root=document_root, **kwargs)\n","sourceCodeStart":19,"sourceCodeEnd":41,"githubUrl":"https://github.com/django/django/blob/b5388a3a80cafcce2e34196d8e81cf5b48eb33bb/django/contrib/staticfiles/views.py#L19-L41","documentation":"Raised as Http404 from staticfiles serve() view when the requested path maps to a directory (path ends with '/' or is empty) and finders cannot resolve it to a file. The staticfiles dev view does not support directory listing, so a directory request is rejected with a 404 carrying this message rather than listing contents.","triggerScenarios":"A request to the static serve URL with a trailing slash or empty path, in DEBUG=True (or with insecure=True), where finders.find(normalized_path) returns None. E.g. GET /static/css/ resolves to nothing.","commonSituations":"Browsing to a static directory in the dev server expecting an index; a template/JS building a URL that ends in '/' pointing at a folder; a typo that drops the filename.","solutions":["Request a specific file, not a directory (remove trailing slash and add a filename).","If you need directory listings, serve files another way (staticfiles dev view intentionally disallows it).","Correct the URL-building code so it always targets a real asset."],"exampleFix":"<!-- before -->\n<img src=\"{% static 'images/' %}\">  <!-- directory -> 404 -->\n\n<!-- after -->\n<img src=\"{% static 'images/logo.png' %}\">","handlingStrategy":"try-catch","validationCode":"from django.contrib.staticfiles import finders\n\npath = request.path.strip(\"/\")\nif not path or path.endswith(\"/\"):\n    raise ValueError(\"Directory listing not supported\")\nif not finders.find(path.rstrip(\"/\")):\n    raise ValueError(\"Static file not found\")","typeGuard":null,"tryCatchPattern":"from django.http import Http404\n\ntry:\n    response = serve(request, path)\nexcept Http404 as e:\n    logger.info(\"Static not found: %s\", e)\n    raise","preventionTips":["Always reference concrete files in templates, never directory paths.","In dev, type a full filename in the browser rather than a folder.","Validate generated static URLs don't end with '/'."],"tags":["staticfiles","http404","dev-server","directory-index"],"backgroundTag":null,"analyzedSha":"b5388a3a80cafcce2e34196d8e81cf5b48eb33bb","analyzedAt":"2026-08-10T17:37:52.993Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}