retspen / webvirtcloud

WebVirtCloud is virtualization web interface for admins and users
1.7k stars 372 forks source link

Rework Static_Root & StaticFile structure #623

Open MisterBlueBear opened 1 year ago

MisterBlueBear commented 1 year ago

These changes fix the django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path as seen in #622 and #605.

Static files in the static directory are moved to webvirtcloud/static and framework component files (i.e. rest_framework/* and drf-yasg/*) are deleted as they will be copied / linked by collectstatic. Also, instead of copying static files into the static directory, I think using symbolic links (--link) will be better as it uses less disk space and the --clear removes orphan static files which may no longer be part of a framework component or the WVC static directory.

python3 manage.py collectstatic --noinput --clear --link

Note: When updating WVC, the below code in webvirtcloud/settings.py

if not DEBUG:
    STATIC_ROOT = ""

STATICFILES_DIRS = [
    Path.joinpath(BASE_DIR, "static"),

]

must be replaced with

STATIC_ROOT = "static"

STATICFILES_DIRS = [
    Path.joinpath(BASE_DIR, "webvirtcloud/static"),
]

The webvirtcloud/settings.py.template is up-to-date with the changes so a new installation will work out-of-the-box.

I commented and posted additionnal explanations for these changes at https://github.com/retspen/webvirtcloud/issues/605#issuecomment-1783447441

catborise commented 1 year ago

changing static files structure is not appropriate, because there will be to two copy of static files. one of them static/, other one webvirtcloud/webvirtcloud/static. whitenoise project solves this static problem. i hope it will fix for every scenario. to using whitenoise on development/locale, --nostatic parameter must be added manage.py runserver command

MisterBlueBear commented 1 year ago

@catborise I was just following the django 4.2 docs for STATIC_ROOT which says :

This should be an initially empty destination directory for collecting your static files from their permanent locations into one directory for ease of deployment; it is not a place to store your static files permanently. You should do that in directories that will be found by staticfiles’s finders, which by default, are 'static/' app sub-directories and any directories you include in STATICFILES_DIRS).