django中如何暴露后端任意文件资源
通用方法:
1、先去配置文件中写下面的一句配置
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
2、导入模块以及配置文件
from django.views.static import serve
from xxx(你的项目名) import settings
3、在urls中写下面的路由视图配置(固定写法)
url(r'^media/(?P<path>.*)', serve, {"document_root":settings.MEDIA_ROOT })
Only you can control your future
You're not alone. You still have family,peopel who care for you and want to save you.