[英]How to serve static media with Daphne 2.0 on django
我是daphne的新手,我想知道如何在ubuntu服务器上部署在daphne上运行的django应用程序。 我已经按照文档中所述配置了该应用程序,并且可以正常运行,但不会加载静态文件(js,css,imgs等)。 我需要做什么?
使用这些设置,它们对我来说效果很好。 我们在这里有两个单独的文件夹。 一种用于媒体文件,另一种用于静态文件。
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")
抱歉,是一个错误。 我最近注意到,当我使用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上无效。
除了
安德鲁·戈德温(达芙妮和频道的负责人)评论了我
“达芙妮将只通过runserver在本地开发人员的同一进程中提供静态文件-部署到生产环境后,您需要运行collectstatic并分别提供静态文件,您可以在此处阅读: https : //docs.djangoproject.com/en /2.0/howto/static-files/deployment/#serving-static-files-in-production “
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.