2012-08-05 101 views
0

我是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. 
) 

請讓我知道我錯了。提前致謝。

乾杯 小號

回答

1

是您的DEBUG設置設爲True對Heroku的?如果不是,appmedia.urls不會包括在內。

相關提示,django-appmedia不是在Django處理靜態資產的最好方式 - 爲Django的1.3,有一個名爲staticfiles一個的contrib應用程序(見:https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/),以及Heroku的預期,您將使用該應用程序。

此外,django-appmedia似乎希望在每個應用程序中一個/media/目錄中的資產,而staticfiles預計資產將在每個應用程序的文件夾/static/

你看過Django上的Heroku文檔和靜態資產https://devcenter.heroku.com/articles/django-assets

+0

嗨Jason。我已經在使用staticfiles應用程序,並且我在本地進行了靜音。同樣,這在當地很好,但在Heroku上沒有問題。 – werty37 2012-08-05 17:21:25

+0

另外我檢查了圖像的URL和它從靜態文件夾中提供。例如:「/static/cms/images/pony.jpg」 – werty37 2012-08-05 17:22:23

+0

另一個有趣的發現。即使在本地,圖像和css也只能用django內置的服務器和NIT以gunicorn或工頭啓動。 – werty37 2012-08-05 17:36:26

相關問題