2012-11-14 43 views
3

我有一个项目,实际上是从appfog(https://github.com/appfog/af-python-django)在本地主机上运行平稳的测试。但它不起作用,至少静态文件一旦部署在appfog上就无法识别。 我改变了tempaltes的位置。appfog django静态文件

这是测试页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" %}

回答

2

这个工作对我来说:

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}), 
+0

好,这可以是一个解决方案,但文档说不使用django来提供静态文件。 https://docs.djangoproject.com/zh/dev/howto/static-files/#serving-static-files-in-production and this https://docs.djangoproject.com/zh/dev/howto/static-files/#services-static-files-in-development(警告) – EsseTi

+1

这是真的,但是现在除了在外部服务器上托管静态文件之外,没有其他方法可以这样做。 –

+0

看到这个:http://stackoverflow.com/questions/13208293/how-to-serve-static-content-with-apache-in-appfog-wsgi-python-app/14085389#14085389 – Anoyz