static-files

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

How to load a different file than index.html in FastAPI root path? Question: Here is a simple static FastAPI app. With this setup even though the root path is expected to return a FileResponse of custom.html, the app still returns index.html. How can I get the root path work and render custom.html? from fastapi import …

Total answers: 1

FastAPI serving static files through symlinks

FastAPI serving static files through symlinks Question: I have mounted the static directory in my FastAPI app using the following code: from fastapi.staticfiles import StaticFiles app = FastAPI( title="Title of the Application", description="Over all description of the application") app.mount("/public", StaticFiles(directory=’public’), name=’public’) If I have a symlink pointing to a path outside the app folder, e.g. …

Total answers: 1

FastAPI not loading static files

FastAPI is not loading static files Question: So, I’m swapping my project from node.js to python FastAPI. Everything has been working fine with node, but here it says that my static files are not present, so here’s the code: from fastapi import FastAPI, Request, WebSocket from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from fastapi.templating …

Total answers: 3

What's the point of Django's collectstatic?

What's the point of Django's collectstatic? Question: In Django, the convention is to put all of your static files (i.e css, js) specific to your app into a folder called static. So the structure would look like this: mysite/ manage.py mysite/ –> (settings.py, etc) myapp/ –> (models.py, views.py, etc) static/ In mysite/settings.py I have: STATIC_ROOT …

Total answers: 4

'collectstatic' command fails when WhiteNoise is enabled

'collectstatic' command fails when WhiteNoise is enabled Question: I’m trying to serve static files through WhiteNoise as per Heroku‘s recommendation. When I run collectstatic in my development environment, this happens: Post-processing ‘css/iconic/open-iconic-bootstrap.css’ failed! Traceback (most recent call last): File “./manage.py”, line 10, in <module> execute_from_command_line(sys.argv) File “/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/__init__.py”, line 385, in execute_from_command_line utility.execute() File “/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/__init__.py”, line …

Total answers: 16

ImproperlyConfigured at / Empty static prefix not permitted – Django

ImproperlyConfigured at / Empty static prefix not permitted – Django Question: I’m working on uploading/displaying images with Django. The website is deployed on Heroku. Following this tutorial I was able to successfully upload images. However, the images weren’t being displayed in the template. I then learned that my urls.py should have this line at the …

Total answers: 9

How to serve static files in Flask

How to serve static files in Flask Question: So this is embarrassing. I’ve got an application that I threw together in Flask and for now it is just serving up a single static HTML page with some links to CSS and JS. And I can’t find where in the documentation Flask describes returning static files. …

Total answers: 24

With Flask, how can I serve robots.txt and sitemap.xml as static files?

With Flask, how can I serve robots.txt and sitemap.xml as static files? Question: I’ve read on quiet a few places that serving static files should be left to the server, for example in a couple of the answers on this SO question. But I use the OpenShift PaaS, and can’t figure out how to modify …

Total answers: 3

Disable static file caching in Tornado

Disable static file caching in Tornado Question: By default, Tornado puts a Cache-Control: public header on any file served by a StaticFileHandler. How can this be changed to Cache-Control: no-cache? Asked By: Jordan || Source Answers: Looking into the tornado/web.py it seems that the easiest way is to subclass the StaticFileHandler and override the set_extra_headers …

Total answers: 2

Django — Can't get static CSS files to load

Django — Can't get static CSS files to load Question: I’m running Django’s development server (runserver) on my local machine (Mac OS X) and cannot get the CSS files to load. Here are the relevant entries in settings.py: STATIC_ROOT = ‘/Users/username/Projects/mysite/static/’ STATIC_URL = ‘/static/’ STATICFILES_DIRS = ( ‘/Users/thaymore/Projects/mysite/cal/static’, ) STATICFILES_FINDERS = ( ‘django.contrib.staticfiles.finders.FileSystemFinder’, ‘django.contrib.staticfiles.finders.AppDirectoriesFinder’, #’django.contrib.staticfiles.finders.DefaultStorageFinder’, …

Total answers: 21