[英]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.