4

我是 daphne 的新手,我想知道如何在 ubuntu 服务器上部署在 daphne 上运行的 django 应用程序。我已经像文档中所说的那样配置了应用程序,并且工作正常,除了静态文件(js、css、imgs 等)没有加载。我需要做什么?

4

2 回答 2

2

对不起,是一个错误。我最近注意到,当我使用 Channels 1.8 时,我在生产环境的 routing.py 上有这段代码

from channels.staticfiles import StaticFilesConsumer
from . import consumers

channel_routing = {
    # This makes Django serve *emphasized text*static files from settings.STATIC_URL, similar
    # to django.views.static.serve. This isn't ideal (not exactly production
    # quality) but it works for a minimal example.
    'http.request': StaticFilesConsumer(),
    # Wire up websocket channels to our consumers:
   'websocket.connect': consumers.ws_connect,
   'websocket.receive': consumers.ws_receive,
   'websocket.disconnect': consumers.ws_disconnect,
}

很可能就是这个原因。1.8 上的工作正常,而 2.0 不工作。

除了

安德鲁·戈德温(达芙妮和频道的管理员)评论了我

“Daphne 将仅通过 runserver 在本地开发中提供来自同一进程的静态文件 - 一旦部署到生产环境,您需要单独运行 collectstatic 并提供静态文件,您可以在此处阅读:https ://docs.djangoproject.com/en /2.0/howto/static-files/deployment/#serving-static-files-in-production "

于 2018-02-13T20:06:10.847 回答
-1

使用这些设置,它们对我来说效果很好。我们这里有两个单独的文件夹。一种用于媒体文件,另一种用于静态文件。

STATIC_URL = '/static/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static_my_proj"),
]

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn", 
"static_root")

MEDIA_URL = '/media/'
MEDIA_ROOT = 
os.path.join(os.path.dirname(BASE_DIR),"static_cdn","media_root")
于 2018-02-09T23:01:15.133 回答