So I am working on a Django (1.9) project, and have the need to use the same templates and static files across multiple apps. I know how to use templates and static files stored outside each app (using STATICFILES_DIRS and TEMPLATEFILES_DIRS in settings.py), but where should I store them?
My guess would be in folders in the project directory.
home/user/myproject/staticfiles home/user/myproject/templates
But if there are official reconsiderations (which I have been unable to find in the documentation), I would prefer to comply with those.
Also, if there are any other recommendations for using templates and static files outside of the normal django app directories, that you think I should know about, I'd really appreciate you telling me (or telling me where to look).
Cheers :)
Apps in the standard environment can serve static files from a Google Cloud option like Cloud Storage, serve them directly, or use a third-party content delivery network (CDN). Hosting your static site on Google Cloud can cost less than using a traditional hosting provider, as Google Cloud provides a free tier.
Serving static files in production. The basic outline of putting static files into production consists of two steps: run the collectstatic command when static files change, then arrange for the collected static files directory ( STATIC_ROOT ) to be moved to the static file server and served.
Static files are meant for javascript/images etc, but media files are for user-uploaded content.
Assume there is a global css file located here: home/user/myproject/staticfiles/css/global.css
Change settings.py to match this:
STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, "staticfiles"), ]
Inside of a template, for example, index.html:
{% load static %} <link rel="stylesheet" type="text/css" href="{% static 'css/global.css' %}" />
Now Django can find global.css.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With