DISCLAIMER: I know there's lots of questions here for 404
on static resources in django
, but unfortunately none of it helps :(
Problem: as stated in title, I got 404
response for all static resources in graphite
web app.
Here are some relevant config parts:
app_settings.py:
INSTALLED_APPS = (
'graphite.metrics',
'graphite.render',
'graphite.browser',
'graphite.composer',
'graphite.account',
'graphite.dashboard',
'graphite.whitelist',
'graphite.events',
'graphite.url_shortener',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.staticfiles',
'tagging',
)
settings.py:
# Defaults for these are set after local_settings is imported
STATIC_ROOT = ''
STATIC_URL = ''
...
## Load our local_settings
try:
from graphite.local_settings import * # noqa
except ImportError:
print >> sys.stderr, "Could not import graphite.local_settings, using defaults!"
...
STATICFILES_DIRS = (
join(WEBAPP_DIR, 'content'),
"/opt/graphite/webapp/content/",
)
if not STATIC_ROOT:
STATIC_ROOT = join(GRAPHITE_ROOT, 'static')
...
# Handle URL prefix in static files handling
if URL_PREFIX and not STATIC_URL.startswith(URL_PREFIX):
STATIC_URL = '/{0}{1}'.format(URL_PREFIX.strip('/'), STATIC_URL)
local_settings.py:
STATIC_ROOT = '/opt/graphite/webapp/content/'
STATIC_URL = '/content/'
STATICFILES_DIRS = (
# os.path.join(BASE_DIR, "static"),
# os.path.join(BASE_DIR, "content"),
"/opt/graphite/webapp/content/",
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
...
from graphite.app_settings import *
Django version:
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 4, 14, 'final', 0)
Directories layout:
/opt/graphite/
/webapp/
/graphite/
/content/ <-- static files I want placed right here
/opt/graphite
is actually a symlink to another folder, if that matters.
I got 404 errors for the urls like this:
http://my_host:9999/content/js/...
http://my_host:9999/content/css/...
I have also tried collectstatic
command with no success:
[root@myserver graphite]# pwd
/opt/graphite/webapp/graphite
[root@myserver graphite]# python manage.py collectstatic
Could not import graphite.local_settings, using defaults!
Unknown command: 'collectstatic'
Type 'manage.py help' for usage.
[root@myserver graphite]# django-admin collectstatic --noinput --settings=graphite.settings
Unknown command: 'collectstatic'
Type 'django-admin help' for usage.
[root@myserver graphite]# python manage.py collectstatic --noinput --settings=graphite.settings
Unknown command: 'collectstatic'
Type 'manage.py help' for usage.
Django is started in the following way:
/usr/bin/django-admin runserver --pythonpath /opt/graphite/webapp --settings graphite.settings 0.0.0.0:9999 &
Any help will be high appreciated.
UPD: I have upgraded django
to 1.5 and changed some paths:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "content"),
)
STATIC_ROOT = ''
STATIC_URL = 'static'
After that, collectstatic
command finally worked and copied all files to /opt/graphite/static
dir. I decided to try DEBUG = True
and a miracle happened - finally I got all static files I wanted, but when I reverted it to default settings, 404
again.
Firstly, it looks like you are trying to use latest Graphite with an old version of Django, is that correct?
Master branch of graphite needs Django >= 1.4 which would give you the collectstatic command.
The correct command for collectstatic also needs the pythonpath so it picks up the correct graphite settings - python manage.py collectstatic --pythonpath=/opt/graphite/webapp
.
Collectstatic needs to run without errors and you should see the files in /opt/graphite/webapp/content. After that if you see 404s for files that do exist on the filesystem location then there's something wrong with your webapp settings (started without pythonpath for example).
As I wrote in the question, setting DEBUG = True
actually solves the problem. That is because django
doesn't handle static files if started in dev mode: Why does DEBUG=False setting make my django Static Files Access fail?
So, the solution for the dev mode server includes:
django
to 1.5;STATIC_ROOT
to ''
(works for Graphite);STATICFILES_DIRS
;python manage.py collectstatic --pythonpath=/opt/graphite/webapp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With