3

I've a project, actually is the test from appfog (https://github.com/appfog/af-python-django) that run smoothly in localhost. But it does not work, at least static files are not recognized once deployed on appfog. I've changed just the location of tempaltes.

This is the test page http://st-test.eu01.aws.af.cm/ . as well, also the admin pages are without css http://st-test.eu01.aws.af.cm/admin/

this is my configuration (setting.py)

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = (
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

i also tried with

STATIC_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static')

but nothing changes.

i've tried with doing collectstatic locally and then update the files on the repository, but nothing works.

does anyone of you know how to make it working?

btw, in the template i use {% load staticfiles %} and {% static "css/style.css" %}

EsseTi
  • 4,079
  • 5
  • 36
  • 63

1 Answers1

2

This works for me:

settings.py:

import os
ROOT_PATH = os.path.dirname(__file__)

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

urls.py:

(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
  • well, this can be a solution but the docs says to not use django to serve static files. https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production and this https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-development (the warning) – EsseTi Nov 26 '12 at 17:30
  • 1
    That is true, however right now there isn't any other way to do it, other than hosting the static files on an external server. – Bonjour Tristesse Nov 27 '12 at 03:20
  • see this: http://stackoverflow.com/questions/13208293/how-to-serve-static-content-with-apache-in-appfog-wsgi-python-app/14085389#14085389 – Anoyz Jun 02 '13 at 20:38