标签:root col ges 文件配置 mep div dia class height
1.sttings中配置 ‘django.template.context_processors.media‘
TEMPLATES = [ { ‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘, ‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘)] , ‘APP_DIRS‘: True, ‘OPTIONS‘: { ‘context_processors‘: [ ‘django.template.context_processors.debug‘, ‘django.template.context_processors.request‘, ‘django.contrib.auth.context_processors.auth‘, ‘django.contrib.messages.context_processors.messages‘, ‘django.template.context_processors.media‘, ], }, }, ]
2.在静态页面中设置
{{ MEDIA_URL }}{{ course_org.image }}
{% for course_org in all_org %} <dl class="des difdes"> <dt> <a href="org-detail-homepage.html"> <img width="200" height="120" class="scrollLoading" data-url="{{ MEDIA_URL }}{{ course_org.image }}"/> </a> </dt> <dd>
3.在路由设置
from django.views.static import serve # 处理静态文件的
from studyimooc.settings import MEDIA_ROOT
# 配置上传文件的函数 url(r‘^media/(?P<path>.*)$‘, serve, {"document_root": MEDIA_ROOT})
标签:root col ges 文件配置 mep div dia class height
原文地址:https://www.cnblogs.com/dream-hh/p/9966031.html