Search code examples
djangolighttpd

Handling static files with Django / lighttpd


I know that there is already a question (actually some more) about this, but the answers to them didn't help me out very much, as I am pretty new to lighttpd.

I have one folder which contains .pdf-files. When doing a HttpResponseRedirect to the locations of one of those .pdf-files, the user should be able to download the .pdf file (or view it in the browser). Right now, Django just redirects to my "home" html page, without showing any pdf-file.

Somehow, I will have to tell lighttpd that Django shouldn't handle this directory anymore. Is this the only thing I need to do? If yes, how should i do it?


Solution

  • Did you see the section "lighttpd setup" in the Django docs? Using alias.url an url.rewrite-once you can route the requests to you app or a folder serving files:

    alias.url = (
        "/pdfs" => "/path/to/my/pdfs",
    )
    
    url.rewrite-once = (
        "^(/pdfs.*)$" => "$1",
        "^(/.*)$" => "/mysite.fcgi$1",
    )