其他分享
首页 > 其他分享> > 【Django】static 静态文件, media 文件设置

【Django】static 静态文件, media 文件设置

作者:互联网

1. settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'statics')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'medias')

2. urls.py

from . import settings
from django.conf.urls import re_path
from django.views.static import serve

urlpatterns = [
    re_path('static/(?P<path>.*)', serve, {'document_root': settings.STATIC_ROOT}),
    re_path('media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT}),
]

标签:文件,settings,media,Django,re,static,path,ROOT
来源: https://www.cnblogs.com/jessecheng/p/16189605.html