Django – Static file not found

I confused STATIC_ROOT and STATICFILES_DIRS Actually I was not really understanding the utility of STATIC_ROOT. I thought that it was the directory on which I have to put my common files. This directory is used for the production, this is the directory on which static files will be put (collected) by collectstatic. STATICFILES_DIRS is the … Read more

Prevent IIS from serving static files through ASP.NET pipeline

I’m taking a guess here and suspect that you have the following setting configured in your web.config file: <modules runAllManagedModulesForAllRequests=”true”> This means that every request, including those for static content is hitting the pipeline. Change this setting to: <modules runAllManagedModulesForAllRequests=”false”> This is assuming your application is running under ASP.NET 4.0 and MVC3. For this to … Read more

How to load a different file than index.html in FastAPI root path?

As per Starlette documentation: StaticFiles Signature: StaticFiles(directory=None, packages=None, check_dir=True) html – Run in HTML mode. Automatically loads index.html for directories if such file exists. In addtion, as shown from the code snippet you provided, you have mounted StaticFiles to the root directory (i.e., “https://stackoverflow.com/”), instead of, for example, /static (or some other path name), as … Read more

‘collectstatic’ command fails when WhiteNoise is enabled

The problem here is that css/iconic/open-iconic-bootstrap.css is referencing a file, open-iconic.eot, which doesn’t exist in the expected location. When you run collectstatic with that storage backend Django attempts to rewrite all the URLs in your CSS files so they reference the files by their new names e.g, css/iconic/open-iconic.8a7442ca6bed.eot. If it can’t find the file it … Read more

Django — Can’t get static CSS files to load

Read this carefully: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/ Is django.contrib.staticfiles in your INSTALLED_APPS in settings.py? Is DEBUG=False? If so, you need to call runserver with the –insecure parameter: python manage.py runserver –insecure collectstatic has no bearing on serving files via the development server. It is for collecting the static files in one location STATIC_ROOT for your web server to … Read more

How to serve all existing static files directly with NGINX, but proxy the rest to a backend server.

Use try_files and named location block (‘@apachesite’). This will remove unnecessary regex match and if block. More efficient. location / { root /path/to/root/of/static/files; try_files $uri $uri/ @apachesite; expires max; access_log off; } location @apachesite { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } Update: The assumption of this config is that … Read more

Use nginx to serve static files from subdirectories of a given directory

It should work, however http://nginx.org/en/docs/http/ngx_http_core_module.html#alias says: When location matches the last part of the directive’s value: it is better to use the root directive instead: which would yield: server { listen 8080; server_name www.mysite.com mysite.com; error_log /home/www-data/logs/nginx_www.error.log; error_page 404 /404.html; location /public/doc/ { autoindex on; root /home/www-data/mysite; } location = /404.html { root /home/www-data/mysite/static/html; } … Read more

Django Static Files Development

Based on what you’ve posted so far, it looks like you’re following the docs for django.contrib.staticfiles. I agree that the docs can be difficult to follow especially if one is new to django. I believe the confusion stems from the fact that django.contrib.staticfiles has two modes of operation: During the development phase where the development … Read more