【问题标题】:heroku deploy error with static root path django. static_root not set to file system pathheroku 使用静态根路径 django 部署错误。 static_root 未设置为文件系统路径
【发布时间】:2018-09-04 04:12:03
【问题描述】:

当我尝试部署时,我的静态文件设置根据 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)),
]

【问题讨论】:

    标签: python django heroku collectstatic


    【解决方案1】:

    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)
    

    【讨论】:

    • 感谢您的快速回答!我刚刚用我的根网址上传了我的问题。在我给定的情况下,您的答案仍然有效吗?我要试试你的答案
    • 是的。仍然有效并尝试。
    • 只是累了。我做了 git commit 等等。以同样的错误推送到 heroku django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
    • 您的static 目录是否与manage.py 处于同一级别??
    • 但不是在我运行 collectstatic 时创建的吗?
    猜你喜欢
    • 2014-05-26
    • 1970-01-01
    • 2020-07-20
    • 2020-07-28
    • 2018-07-05
    • 2013-06-06
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    相关资源
    最近更新 更多