[英]How to serve static files in django 3.1
當我在我的設置中有選項DEBUG = True
時,我使用django 3.1
3.1。py static 文件可以正常使用,但是當我使用DEBUG = False
時,ZA81259CEF8E959C624DF1D4 文件未准備好使用 I56E5
在 django 的官方文檔中的答案中使用這個:
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
但仍然不起作用。 有人知道為什么仍然不起作用。
你可以添加這個
設置.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = (
os.path.join(BASE_DIR, 'staticfiles')
)
MEDIA_URL = '/media/'
MEDIA_ROOT = (
os.path.join(BASE_DIR, 'media')
)
mkdir static
python manager.py collectstatic --noinput
python manager.py runserver
有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.