I am utterly lost on one of the last steps of this project.
So far, I've been able to develop a django app that works the way I want it to on localhost; I've been able to deploy the website to AWS EC2, but I must be missing something fundamental about serving the static files. (I haven't even tried media files yet.) I've read the Django Deployment page and How-To manage static files, but I have never deployed a website from scratch before. The tutorials I've found seem to be contradicting (or outdated?).
Here are the questions I think I have at this time:
- Do I need to host static (and/or media) files in a bucket, or is this merely a good idea?
- When I set up STATIC_ROOT and STATIC_URL, should I have a STATICFILE_DIRS setup? (I mean, I think I really need a tutorial on how they even go together, their settings, and how 'static' works in the templates.)
- I've tried to get whitenoise going; I get a message that STATIC_URL isn't set up correctly; I can't find the documentation to tell me what it should be. Is this a viable root to take?
EDIT
Even with @DirkGroten 's amazingly detailed answer, I'm still not getting how to serve static files. I can run the server and then web browser in to see pages with no static files. But, I now have a new problem: Pages that have static files on them return a 500 27 error (whereas they used to return an error for only the file). So, here is my folder structure, and below that is the relevant part of my settings file (which is actually split into base, dev, and prod).
[mainsite]/
|---[mainsite]/
| |---[settings]/
| |---base.py
| |---dev.py
| |---prod.py
|---[app1]/
| |---[migrations]
| |---[static]/
| | |---[app1]/
| | | |---app1_file1.jpg (etc)
| | |---app1_style.css
| |---[templates]/
| | |---[app1]/
| | |---about.html (etc)
|---[app2]/ (etc)
|---[static] (this gets populated after running collectstatic)
development settings:
Debug = False
ALLOWED_HOSTS = [###.###.###.###]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
... (the rest of the middleware)
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.abspath(os.path.join(BASE_DIR, 'static'))
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'app1/'),
os.path.join(BASE_DIR, 'app2/'),
os.path.join(BASE_DIR, 'app3/'),
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
I have made sure that I am importing whitnoise in production requirements file.
What am I missing?
Also, I have never used the AWS support system. (I'm on the free tier.) Is this the kind of thing I can get their help on? Do I start a case?
TIA.