I am well aware that the issue in the title is already a popular subject, however, I have not found a solution that has worked for me. I am trying to have my site serve static files, I have done all the steps that I know of.
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
This is my static definition in settings.py. I have executed the command collectstatic --noinput. The folder was generated.
In the web tab of PythonAnywhere, I put /static/ in the URL and /home/username/.virtualenvs/venv/Django/project/staticfiles.
My security settings in settings.py are:
if DEBUG:
SECURE_BROWSER_XSS_FILTER = False
SECURE_CONTENT_TYPE_NOSNIFF = False
X_FRAME_OPTIONS = 'DENY'
SECURE_SSL_REDIRECT = False
SECURE_HSTS_SECONDS = 0
SECURE_HSTS_PRELOAD = False
SECURE_HSTS_INCLUDE_SUBDOMAINS = False
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
else:
# Set stronger security settings for production
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
X_FRAME_OPTIONS = 'DENY'
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 86400
SECURE_HSTS_PRELOAD = True
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
As far as i understand, I have all the / in the right places and paths pointing to the right directory.
Source code points to /home/username/.virtualenvs/venv/Django/project
Any help is appreciated because I have tried Google, GPT, other forums posts and Youtube videos where it just works but for some reason, I am having trouble.