Heroku使用静态根路径Django部署错误.static_root未设置为文件系统路径



当我尝试部署时,根据Heroku对我的静态文件设置进行了不当配置。毫无疑问,这是错误的,因为我仍然缺乏对设置静态文件的正确方法的了解。

我在机器上跑了静态,而且确实有效。我将提供我的要求的信息,以帮助我清除此信息。我将继续研究并希望提供解决方案。

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#angular distro root
ANGULAR_APP_DIR = os.path.join(BASE_DIR, 'frontend/dist')

STATICFILES_DIRS = [
    os.path.join(ANGULAR_APP_DIR),
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

这些是我当前的根网址:

urlpatterns = [
    url(r'^$', serve, kwargs={'path': 'index.html'}),
    url(r'^(?!/?static/)(?!/?media/)(?P<path>.*..*)$',RedirectView.as_view(url='/static/%(path)s', permanent=False)),
    url(r'api/',include(rootapi)),
]

STATIC_URL添加到您的urlpatterns

from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
    # your url patterns
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

相关内容

最新更新