Django Compressor not using STATICFILES_FINDER from settings - django

I'm trying to use Django Compressor, which seems pretty straight-forward, but for some reason I keep getting an error, specifically:
When using Django Compressor together with staticfiles, please add 'compressor.finders.CompressorFinder' to the STATICFILES_FINDERS setting
My settings.py file includes the following:
DEBUG = True
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
...
'compressor',
)
STATIC_URL = '/static/'
STATICFILES_FINDER = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder'
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, '_static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
COMPRESS_ENABLED = True
I'm not sure if this is a compatibility issue with Django 1.10 (Django Compressor changelog states it is compatible with 1.10), or if Django Compressor simply is broken, since I've clearly added 'compressor.finders.CompressorFinder' to the STATICFILES_FINDERS setting. I've also tried with DEBUG=False.
Any help is appreciated.

Related

CSS file references a file which could not be found. (Fieldsets forms and Heroku)

I am using fieldsets for my django forms.
Everything works fine on local. I wanted to uploaded onto Heroku and started running into problem.
When running "python manage.py collectstatic", I am getting the following error:
The CSS file 'forms_fieldset\css\main.css' references a file which could not be found: forms_fieldset/img/sorting-icons.svg
The message is correct. The file forms_fieldset/img/sorting-icons.svg is not mentioned in main.css.
I suppose there is two questions:
How does it know a file does not exist, if it actually not mentioned
anywhere?
How and where can I add this file?
Below is my settings.py, just in case someone wants to look at it:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"crispy_forms",
'main.apps.MainConfig',
'register.apps.RegisterConfig',
'import_export',
'forms_fieldset',
]
...
STATIC_URL = 'static/'
#IMAGE STUFF#
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
#Staticfiles_storage to make it compatible with Heroku
SATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
#storing static files
VENV_PATH = os.path.dirname(BASE_DIR)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),)

Using Whitenoise but still can not serve static files

I'm trying to serve static files in my product review website, and I'm using Whitenoise, but It didn't work (can not find the files in /static) (when I test on local with DEFAULT = False, it still works)
I've tried to config wsgi file instead of using whitenoise middleware
This is my some code in my settings file to serve static.
DEBUG = False
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'djangobower.finders.BowerFinder',
)
Can you show me how to fix it? Pardon for my English
I tried to config the settings again:
DEBUG = False
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# I don't have STATICFILES_DIRS, is it wrong?
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'djangobower.finders.BowerFinder',
)
But it still can not serve static files
I believe what you're missing is the STATICFILES_STORAGE. This is my settings.py related configuration.
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
ALLOWED_HOSTS = ["*"]
I followed the below configuration settings to resolve the issue.
DEBUG = False
ALLOWED_HOSTS = ['testnewapp.herokuapp.com']
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'widget_tweaks',
'phonenumber_field',
'django_extensions',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
# Whitenoise Storage Class - Apply compression but don’t want the caching behaviour
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
# Comment the below line
# django_heroku.settings(locals())
Things to Remember
Make sure you’re using the static template tag to refer to your static files, rather that writing the URL directly. For example:
{% load static %}
<img src="{% static "images/error.jpg" %}" alt="OOps!" />
<!-- DON'T WRITE THIS -->
<img src="/static/images/error.jpg" alt="OOps!" />
If you get an error message with collectstatic, simply disable it by instructing Heroku to ignore running the manage.py collecstatic command during the deployment process.
But if you need to use WhiteNoise with any WSGI application
You need to wrap your existing WSGI application in a WhiteNoise instance and tell it where to find your static files. For example:
from my_project import MyWSGIApp
application = MyWSGIApp()
application = WhiteNoise(application, root='/path/to/static/files')
application.add_files('/path/to/more/static/files', prefix='more-files/')
Note
These instructions apply to any WSGI application. However, for Django applications you would be better off using the WhiteNoiseMiddleware class which makes integration easier.
#
http://whitenoise.evans.io/en/stable/base.html

Django static files getting 404

Hello and thanks for your help in advance. I realize this question has been asked and answered in other placed but none of those answers are working for me.
I am new to python and django and have inherited a small webapp. I have a dev environment working on my computer with mostly unchanged code, the only changes being to the database name and password to point to my local mySQL server.
However, when I run the app, everything works except for the static files. I'm getting 404s in the console when trying to retrieve static files and js methods in static are coming up undefined.
The BASE_PATH, STATIC_URL, STATIC_ROOT, STATICFILES_DIR, STATICFILES_FINDERS are all unchanged from the currently working production code, and as far as my beginner eyes can tell are configured correctly according to the documentation and the multiple answers to this question.
Is there something that could be different about what I have installed on my computer that would be causing this? Why else would it be different between production and my local copy? Is there something I have to run to get this working?
Some settings in settings.py:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
'biogen.apps.BiogenConfig',
'msm.apps.MsmConfig',
'tracker.apps.TrackerConfig',
'accounts.apps.AccountsConfig',
'process_manager.apps.ProcessManagerConfig',
'process.apps.ProcessConfig',
'pfd.apps.PfdConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'djangobower',
'rest_framework',
'crispy_forms',
'django_summernote'
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIR = [
os.path.join(BASE_DIR, 'components/static'),
]
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'djangobower.finders.BowerFinder',
]
Included in the templates:
{% load static %}
Thanks again in advance...
Provide something like this:
Consider you have in your project root directory static_files as a source and static as a destination of your static files - you initially place and edit them in static_files (or any other you have):
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static_files'),
os.path.join(BASE_DIR, 'static_files/js'),
os.path.join(BASE_DIR, 'static_files/html'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'static', )
STATIC_URL = '/static/'
Notice it's STATICFILES_DIRS, not STATICFILES_DIR
Then run
python manage.py collectstatic
to collect your static files from static_files to static
Turns out I needed to load all the static files from Bower. All these files are present on production but not on development for some reason!
Try running
python manage.py collectstatic

STATIC_URL Problems

Static files with Django are driving me insane. I'm successfully able to load my template from the directory specified in TEMPLATE_DIRS, but when I try to load my css and js files from the STATICFILES_DIRS it doesn't work.
Below are the relevant parts of my settings.py file:
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/jrubins/Documents/crowdcluster/crowdcluster/Design/websiteDesign/website/',
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)
TEMPLATE_DIRS = (
'/home/jrubins/Documents/crowdcluster/crowdcluster/Design/websiteDesign/website/',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'items'
)
Please let me know if you need more info or if you see something wrong. Thanks in advance.
Looks like I didn't add RequestContext in my render_to_response() in my view. Solved the problem and should have looked closer at the django documentation.
I am having the same problem, but I found this website which has a lot of information that might be able to help
http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/

help, django-admin-tools wont work!

am installing the django-admin-tools module to enhance the default django admin with custom dashboard and menus. I have read the docs like a bazillion times
Set up everything the way docs say, but am still merely seeing the Django Admin the SAME WAY is was before I'd even though of django-admin-tools.
What could be wrong?
Am running Django 1.3 and using OpenSuse 11.3
If it helps, the order of apps in my settings.py is like:
INSTALLED_APPS = (
'admin_tools',
'django.contrib.admin',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#'grappelli', #for a sweet django admin look
# 'django.contrib.admindocs',
'django_extensions',
'fpui', #the footprint front-end ui app
)
More Parts of my settings.py in relation to this problem:
ROOTDIR = os.path.abspath(os.path.dirname(__file__))
ADMIN_TOOLS_MEDIA_URL = ROOTDIR + '/media/admin_tools/'
MEDIA_ROOT = ROOTDIR + '/media/admin_tools/'
ADMIN_TOOLS_THEMING_CSS = 'css/theming.css'
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
ADMIN_TOOLS_INDEX_DASHBOARD = 'footprint.dashboard.CustomIndexDashboard'
ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'footprint.dashboard.CustomAppIndexDashboard'
ADMIN_TOOLS_MENU = 'footprint.menu.CustomMenu'
STATIC_ROOT = ROOTDIR + '/fpui/static/'
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
Had the same problem and finally managed to make it work.
I think your INSTALLED_APPS are ordered correctly - the admin_tools should be before django.contrib.admin. To be absolutely sure push django.contrib.admin below other admin_tools apps too.
The problem is probably somewhere in the other configurations; mine was that admin_tools couldn't access my templates and was running the regular admin instead.
Try the below:
ROOTDIR = os.path.realpath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(ROOTDIR,'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(PROJECT_ROOT,'media/static')
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
ROOT_URLCONF = 'your_project_name.urls'
TEMPLATE_DIRS = (
os.path.join( PROJECT_ROOT, 'templates' ),
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
)
INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#'grappelli', #for a sweet django admin look
# 'django.contrib.admindocs',
'django_extensions',
'fpui', #the footprint front-end ui app
)
Note that I used realpath for ROOTDIR so that symbolic links may be resolved if there are any. Replace the your_project_name with your project name in ROOT_URLCONF.
Other parameters such as ADMIN_TOOLS_INDEX_DASHBOARD, ADMIN_TOOLS_APP_INDEX_DASHBOARD and ADMIN_TOOLS_APP_INDEX_DASHBOARD are optional, remove them for now so they won't affect the default configuration.
Of course also make sure your urls.py is configured as in the admin_tools guide.
Good luck
Check out the order of your INSTALLED_APPS; It might help if you place the django.contrib.admin just below the django-admin-tools, the order here is used for choosing the right /templates/admin directory.
A little bit late, but I had the same problem, which turned out to be caused by the following circumstance: before installing admin-tools I had overridden one of the admin templates (base-site.html) by putting a modified version in my_project/templates/admin. So it would always use this template instead of the admin_tools one. After removing the custom template it worked.