3

我有一个项目,实际上是来自 appfog ( https://github.com/appfog/af-python-django ) 的测试,它在 localhost 中运行顺利。但是它不起作用,至少静态文件一旦部署在appfog上就无法识别。我只改变了模板的位置。

这是测试页面http://st-test.eu01.aws.af.cm/。同样,管理页面也没有 css http://st-test.eu01.aws.af.cm/admin/

这是我的配置(setting.py)

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = (
)

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

我也试过

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

但没有任何改变。

我尝试在本地进行 collectstatic ,然后更新存储库中的文件,但没有任何效果。

你们中有人知道如何使它工作吗?

顺便说一句,在我使用的模板{% load staticfiles %}{% static "css/style.css" %}

4

1 回答 1

2

这对我有用:

设置.py:

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

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

网址.py:

(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
于 2012-11-25T20:08:59.120 回答