我是Django和Heroku的新手。我的安裝在本地工作正常,但是當它推到Heroku時,我無法在我的網站中看到css,js或圖像。heroku - django圖像不會在heroku中工作,但在本地很好地工作
這是我的URL模式:
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'blog.views.home', name='home'),
# url(r'^blog/', include('blog.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^comments/', include('django.contrib.comments.urls')),
url(r'^blog/', include('zinnia.urls')),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
(r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')),
) + urlpatterns
這是我的settings.py
STATIC_ROOT = os.path.join(PROJECT_PATH, "static")
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
請讓我知道我錯了。提前致謝。
乾杯 小號
嗨Jason。我已經在使用staticfiles應用程序,並且我在本地進行了靜音。同樣,這在當地很好,但在Heroku上沒有問題。 – werty37 2012-08-05 17:21:25
另外我檢查了圖像的URL和它從靜態文件夾中提供。例如:「/static/cms/images/pony.jpg」 – werty37 2012-08-05 17:22:23
另一個有趣的發現。即使在本地,圖像和css也只能用django內置的服務器和NIT以gunicorn或工頭啓動。 – werty37 2012-08-05 17:36:26