1

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

我已经在我的机器上运行 collect static 并且它确实有效。我将提供我所要求的信息来帮助我解决这个问题。我将继续研究并希望找到解决方案。

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)),
]
4

1 回答 1

0

添加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)
于 2018-03-26T05:07:09.833 回答