我的django應用程序在本地服務器上運行良好。但是,當我將它部署在Heroku上時,靜態文件不會被提供(獲得404錯誤)。請幫忙!Django靜態文件無法在Heroku上工作
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = patterns('',
url(r'^$', 'product.views.home', name='home'),
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
靜態文件設置:
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "static", "media")
STATIC_ROOT = os.path.join(BASE_DIR, "static", "static_root")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static", "static_dirs"),
)
WSGI文件 -
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "acton.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
try:
from dj_static import Cling
application = Cling(get_wsgi_application())
except:
pass
仍然有同樣的問題! – Deepak
你可以告訴你是否在部署時,在你的終端上運行python manage.py collectstatic命令時出現錯誤? –
不,當我運行'heroku運行python manage.py collectstatic'時 - 我沒有看到錯誤,收集了靜態文件。 heroku上管理員的css文件有什麼奇怪的現象。它只是我遇到問題的前端。 – Deepak