【发布时间】:2014-08-28 22:24:55
【问题描述】:
我正在使用 heroku 来托管我的 Django(1.6) 应用程序(称为“Zen”)。问题是没有显示静态文件。换句话说,我的应用程序中没有 CSS 和 JS,因为它没有找到这些文件。我在这里查看了其他问题,并将我的应用配置如下:
Settings.py:
##### Static asset configuration #####
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
urls.py:
from django.conf.urls.static import static
from zen import settings
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
)
wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zen.settings")
application = Cling(get_wsgi_application())
显然,在使用git push heroku master 推送我的应用程序后,一切正常:
-----> Preparing static assets
Running collectstatic...
69 static files copied to '/app/staticfiles'.
但正如您所见,我的应用程序中没有 CSS (http://obscure-reef-8874.herokuapp.com/)。我查看了我的应用程序的日志,大多数 css 和 js 文件都处于 404 状态...我尝试了所有方法,你能帮帮我吗?
编辑:
我没有找到错误,我重新创建了一个应用程序,它可以工作,很简单。
【问题讨论】:
-
试试
STATIC_ROOT = os.path.join(PROJECT_PATH, 'staticfiles')