05.增加media文件配置
# 1.增加media文件配置
# 1.1 syl/settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # /teach/shiyanlou_project/syl/media
1
2
2
# 1.2 syl/urls.py
from django.conf.urls.static import static
from syl import settings
urlpatterns = [
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 1.3 测试静态文件访问
- 放一个测试图片到
syl/media/linux.jpg
中
http://192.168.56.100:8888/media/linux.jpg
1
- 测试结果
上次更新: 2024/3/13 15:35:10