0

I'm trying to update Wagtail from version 2.8 to the latest 2.15. Also, I had to update from Django 3.0 to 3.2. However, I noticed that when I use STATICFILES_DIRS, the style of the Wagtail admin (2.15) gets distorted as if it's using the files from the old version (2.8).

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)

...

STATICFILES_FINDERS = [
   'django.contrib.staticfiles.finders.FileSystemFinder',
   'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]


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

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'

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

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

Conversely, when I delete the STATICFILES_DIRS, the style on the Wagtail admin gets fixed, but the all the style on my project its gone.

I already checked and it's not the cache. I tried that several times, different browsers, etc.

cbarboza
  • 3
  • 1

2 Answers2

2

Your STATICFILES_FINDERS setting tells Django that it should look for static files in the following places:

  • FileSystemFinder tells it to look in whichever locations are listed in STATICFILES_DIRS;
  • AppDirectoriesFinder tells it to look in the static folder of each registered app in INSTALLED_APPS.

In normal circumstances, STATICFILES_DIRS should not make a difference to Wagtail's own static files. This is because Wagtail's static files are stored within the apps that make up the Wagtail package, and will be pulled in by AppDirectoriesFinder - FileSystemFinder (and STATICFILES_DIRS) do not come into play.

The fact that you're seeing a difference suggests to me that you've previously customised Wagtail's JS / CSS by placing static files within your project's 'static' folder, in a location such as myproject/static/wagtailadmin/css/, to override the built-in files. These customisations would presumably have been made against Wagtail 2.8 and will not behave correctly against Wagtail 2.15. The solution is to remove these custom files from your project.

gasman
  • 23,691
  • 1
  • 38
  • 56
  • And there is a way to remove them and/or just place the original Wagtail static files that are needed? However, is not very clear to me why if I delete STATICFILES_DIRS, the Wagtail style gets fixed, since the static files are pulled in by "in by AppDirectoriesFinder - FileSystemFinder (and STATICFILES_DIRS) do not come into play." – cbarboza Jan 17 '22 at 21:55
  • As I said in the last paragraph - my best guess is that you previously added some files to myproject/static/wagtailadmin/css/ or similar - alongside your project's own static files - to override Wagtail's admin styles. These files will no longer be valid under Wagtail 2.15, and you should delete them. – gasman Jan 17 '22 at 22:50
  • Yes, you were right. I deleted those static files. However, everything worked out after I made new fresh migrations for everything. – cbarboza Jan 18 '22 at 01:39
1

Try changing:

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

to

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

Dan Swain
  • 2,910
  • 1
  • 16
  • 36
  • I don't think this is it. STATIC_ROOT is the location where static files will be served from; STATICFILES_DIRS is a list of locations (in addition to the 'static' folders within each app) containing source files to be copied to STATIC_ROOT when running collectstatic. If you set them to the same thing, you'll be telling it to copy files to the place where they already are. – gasman Jan 17 '22 at 21:14
  • @gasman is correct, I get the following error: ?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting. – cbarboza Jan 17 '22 at 21:47