0

Per other posts on this subject, I followed the advice at https://bestprogrammingblogs.blogspot.com/2021/03/django-static-files-not-working-when-debug-is-false.html to serve static files when debug is false.

The site advises to make changes to Settings and URLs respectively

STATIC_URL = '/static/'

MEDIA_URL = '/media/'

  

if DEBUG:

  STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

else:

  STATIC_ROOT = os.path.join(BASE_DIR, 'static')

  

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

and in URLs

re_path(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
    re_path(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}), 
path('admin/', admin.site.urls),           

For some reason, my local admin works but the AWS admin site does not. Do I need to tune anything on the AWS side to get this working? My environment variables don't explicitly have any static settings at the moment.

  • The article is misleading. Here is some description about [settings](https://stackoverflow.com/questions/66437690/django-html-template-cant-find-static-css-and-js-files/66439076#66439076), here in the question mentioned how [url patterns](https://stackoverflow.com/questions/60859511/django-doesnt-load-css-file/60861806#60861806) are supposed to be added. The best source is [the docs](https://docs.djangoproject.com/en/4.0/howto/static-files/) it mentions'em all, it's just fine. Follow the docs. – Ivan Starostin May 22 '22 at 18:59
  • Note, on production Django is not supposed to serve neither static nor media files. And DEBUG on prod should not be True. Configure Nginx or other web server to serve them. – Ivan Starostin May 22 '22 at 19:02

1 Answers1

0

I'm not sure that article is correct, you have to always define STATIC_ROOT, you can also define STATICFILES_DIRS if you want, both settings are not related to DEBUG status

ahmed
  • 5,430
  • 1
  • 20
  • 36