得到一個名為 django_server 的 Django 項目。當我跑步時python manage.py runserver該頁面按預期顯示然后,如果我跑gunicorn django_server.wsgi:application --bind 0.0.0.0:8000頁面顯示沒有樣式檢查控制臺,可以看到 .css 和 .js 文件都出現以下錯誤來自“ http://0.0.0.0:8000/static/....css ”的資源由于 MIME 類型(“text/html”)不匹配(X-Content-Type-Options:nosniff)而被阻止。在執行 gunicorn 命令的終端中,可以讀取NOT FOUND: /static/rest_framework/css/bootstrap.min.cssNOT FOUND: /static/rest_framework/css/bootstrap-tweaks.min.css...在 settings.py 我提到BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))STATIC_URL = '/static/'STATIC_ROOT = os.path.join(BASE_DIR,'static')
1 回答

慕蓋茨4494581
TA貢獻1850條經驗 獲得超11個贊
你需要運行python manage.py collectstatic。
在你settings.py身上,我建議你使用whitenoise來提供你的文件。
1) pip install whitenoise
2)添加STATICFILES_STORAGEsettings.py
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
3)添加到你MIDDLEWARE的 settings.py
`MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
...
]
添加回答
舉報
0/150
提交
取消